CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
7zStream.cc
Go to the documentation of this file.
1 /* 7zStream.c -- 7z Stream functions
2 2010-03-11 : Igor Pavlov : Public domain */
3 
4 #include <cstring>
5 
6 #include "Types.h"
7 
8 SRes SeqInStream_Read2(ISeqInStream *stream, void *buf, size_t size, SRes errorType) {
9  while (size != 0) {
10  size_t processed = size;
11  RINOK(stream->Read(stream, buf, &processed));
12  if (processed == 0)
13  return errorType;
14  buf = (void *)((Byte *)buf + processed);
15  size -= processed;
16  }
17  return SZ_OK;
18 }
19 
21  return SeqInStream_Read2(stream, buf, size, SZ_ERROR_INPUT_EOF);
22 }
23 
25  size_t processed = 1;
26  RINOK(stream->Read(stream, buf, &processed));
27  return (processed == 1) ? SZ_OK : SZ_ERROR_INPUT_EOF;
28 }
29 
31  Int64 t = offset;
32  return stream->Seek(stream, &t, SZ_SEEK_SET);
33 }
34 
36  const void *lookBuf;
37  if (*size == 0)
38  return SZ_OK;
39  RINOK(stream->Look(stream, &lookBuf, size));
40  memcpy(buf, lookBuf, *size);
41  return stream->Skip(stream, *size);
42 }
43 
44 SRes LookInStream_Read2(ILookInStream *stream, void *buf, size_t size, SRes errorType) {
45  while (size != 0) {
46  size_t processed = size;
47  RINOK(stream->Read(stream, buf, &processed));
48  if (processed == 0)
49  return errorType;
50  buf = (void *)((Byte *)buf + processed);
51  size -= processed;
52  }
53  return SZ_OK;
54 }
55 
57  return LookInStream_Read2(stream, buf, size, SZ_ERROR_INPUT_EOF);
58 }
59 
60 static SRes LookToRead_Look_Lookahead(void *pp, const void **buf, size_t *size) {
61  SRes res = SZ_OK;
62  CLookToRead *p = (CLookToRead *)pp;
63  size_t size2 = p->size - p->pos;
64  if (size2 == 0 && *size > 0) {
65  p->pos = 0;
66  size2 = LookToRead_BUF_SIZE;
67  res = p->realStream->Read(p->realStream, p->buf, &size2);
68  p->size = size2;
69  }
70  if (size2 < *size)
71  *size = size2;
72  *buf = p->buf + p->pos;
73  return res;
74 }
75 
76 static SRes LookToRead_Look_Exact(void *pp, const void **buf, size_t *size) {
77  SRes res = SZ_OK;
78  CLookToRead *p = (CLookToRead *)pp;
79  size_t size2 = p->size - p->pos;
80  if (size2 == 0 && *size > 0) {
81  p->pos = 0;
82  if (*size > LookToRead_BUF_SIZE)
83  *size = LookToRead_BUF_SIZE;
84  res = p->realStream->Read(p->realStream, p->buf, size);
85  size2 = p->size = *size;
86  }
87  if (size2 < *size)
88  *size = size2;
89  *buf = p->buf + p->pos;
90  return res;
91 }
92 
93 static SRes LookToRead_Skip(void *pp, size_t offset) {
94  CLookToRead *p = (CLookToRead *)pp;
95  p->pos += offset;
96  return SZ_OK;
97 }
98 
99 static SRes LookToRead_Read(void *pp, void *buf, size_t *size) {
100  CLookToRead *p = (CLookToRead *)pp;
101  size_t rem = p->size - p->pos;
102  if (rem == 0)
103  return p->realStream->Read(p->realStream, buf, size);
104  if (rem > *size)
105  rem = *size;
106  memcpy(buf, p->buf + p->pos, rem);
107  p->pos += rem;
108  *size = rem;
109  return SZ_OK;
110 }
111 
112 static SRes LookToRead_Seek(void *pp, Int64 *pos, ESzSeek origin) {
113  CLookToRead *p = (CLookToRead *)pp;
114  p->pos = p->size = 0;
115  return p->realStream->Seek(p->realStream, pos, origin);
116 }
117 
118 void LookToRead_CreateVTable(CLookToRead *p, int lookahead) {
120  p->s.Skip = LookToRead_Skip;
121  p->s.Read = LookToRead_Read;
122  p->s.Seek = LookToRead_Seek;
123 }
124 
125 void LookToRead_Init(CLookToRead *p) { p->pos = p->size = 0; }
126 
127 static SRes SecToLook_Read(void *pp, void *buf, size_t *size) {
128  CSecToLook *p = (CSecToLook *)pp;
129  return LookInStream_LookRead(p->realStream, buf, size);
130 }
131 
133 
134 static SRes SecToRead_Read(void *pp, void *buf, size_t *size) {
135  CSecToRead *p = (CSecToRead *)pp;
136  return p->realStream->Read(p->realStream, buf, size);
137 }
138 
Byte buf[(1<< 14)]
Definition: Types.h:189
#define SZ_ERROR_INPUT_EOF
Definition: Types.h:32
static SRes LookToRead_Read(void *pp, void *buf, size_t *size)
Definition: 7zStream.cc:99
unsigned long long int UInt64
Definition: Types.h:88
tuple pp
Definition: createTree.py:17
SRes SeqInStream_ReadByte(ISeqInStream *stream, Byte *buf)
Definition: 7zStream.cc:24
#define RINOK(x)
Definition: Types.h:52
SRes SeqInStream_Read(ISeqInStream *stream, void *buf, size_t size)
Definition: 7zStream.cc:20
static SRes LookToRead_Look_Lookahead(void *pp, const void **buf, size_t *size)
Definition: 7zStream.cc:60
static SRes SecToLook_Read(void *pp, void *buf, size_t *size)
Definition: 7zStream.cc:127
SRes(* Seek)(void *p, Int64 *pos, ESzSeek origin)
Definition: Types.h:159
void LookToRead_CreateVTable(CLookToRead *p, int lookahead)
Definition: 7zStream.cc:118
static SRes LookToRead_Look_Exact(void *pp, const void **buf, size_t *size)
Definition: 7zStream.cc:76
void SecToLook_CreateVTable(CSecToLook *p)
Definition: 7zStream.cc:132
SRes(* Skip)(void *p, size_t offset)
Definition: Types.h:167
static SRes SecToRead_Read(void *pp, void *buf, size_t *size)
Definition: 7zStream.cc:134
ILookInStream s
Definition: Types.h:185
uint32_t T const *__restrict__ uint32_t const *__restrict__ int32_t int Histo::index_type cudaStream_t stream
SRes SeqInStream_Read2(ISeqInStream *stream, void *buf, size_t size, SRes errorType)
Definition: 7zStream.cc:8
SRes LookInStream_SeekTo(ILookInStream *stream, UInt64 offset)
Definition: 7zStream.cc:30
void LookToRead_Init(CLookToRead *p)
Definition: 7zStream.cc:125
int SRes
Definition: Types.h:43
static SRes LookToRead_Skip(void *pp, size_t offset)
Definition: 7zStream.cc:93
ISeekInStream * realStream
Definition: Types.h:186
ESzSeek
Definition: Types.h:155
#define SZ_OK
Definition: Types.h:25
static SRes LookToRead_Seek(void *pp, Int64 *pos, ESzSeek origin)
Definition: 7zStream.cc:112
ILookInStream * realStream
Definition: Types.h:197
#define LookToRead_BUF_SIZE
Definition: Types.h:182
SRes LookInStream_Read2(ILookInStream *stream, void *buf, size_t size, SRes errorType)
Definition: 7zStream.cc:44
SRes(* Read)(void *p, void *buf, size_t *size)
Definition: Types.h:170
SRes LookInStream_Read(ILookInStream *stream, void *buf, size_t size)
Definition: 7zStream.cc:56
long long int Int64
Definition: Types.h:87
size_t size
Definition: Types.h:188
ILookInStream * realStream
Definition: Types.h:204
ISeqInStream s
Definition: Types.h:196
ISeqInStream s
Definition: Types.h:203
SRes(* Read)(void *p, void *buf, size_t *size)
Definition: Types.h:158
size_t pos
Definition: Types.h:187
SRes(* Seek)(void *p, Int64 *pos, ESzSeek origin)
Definition: Types.h:172
SRes LookInStream_LookRead(ILookInStream *stream, void *buf, size_t *size)
Definition: 7zStream.cc:35
unsigned char Byte
Definition: Types.h:60
SRes(* Read)(void *p, void *buf, size_t *size)
Definition: Types.h:139
SRes(* Look)(void *p, const void **buf, size_t *size)
Definition: Types.h:163
tuple size
Write out results.
void SecToRead_CreateVTable(CSecToRead *p)
Definition: 7zStream.cc:139