CMS 3D CMS Logo

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 
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 
58 }
59 
60 static SRes LookToRead_Look_Lookahead(void *pp, const void **buf, size_t *size) {
61  SRes res = SZ_OK;
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;
79  size_t size2 = p->size - p->pos;
80  if (size2 == 0 && *size > 0) {
81  p->pos = 0;
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) {
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) {
119  p->s.Look = lookahead ? LookToRead_Look_Lookahead : LookToRead_Look_Exact;
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 
ILookInStream
Definition: Types.h:162
CSecToRead
Definition: Types.h:202
SecToRead_CreateVTable
void SecToRead_CreateVTable(CSecToRead *p)
Definition: 7zStream.cc:139
Byte
unsigned char Byte
Definition: Types.h:60
CLookToRead
Definition: Types.h:184
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
cms::cuda::stream
cudaStream_t stream
Definition: HistoContainer.h:57
pos
Definition: PixelAliasList.h:18
UInt64
unsigned long long int UInt64
Definition: Types.h:88
LookToRead_CreateVTable
void LookToRead_CreateVTable(CLookToRead *p, int lookahead)
Definition: 7zStream.cc:118
LookInStream_Read2
SRes LookInStream_Read2(ILookInStream *stream, void *buf, size_t size, SRes errorType)
Definition: 7zStream.cc:44
SZ_OK
#define SZ_OK
Definition: Types.h:25
SeqInStream_Read2
SRes SeqInStream_Read2(ISeqInStream *stream, void *buf, size_t size, SRes errorType)
Definition: 7zStream.cc:8
LookInStream_LookRead
SRes LookInStream_LookRead(ILookInStream *stream, void *buf, size_t *size)
Definition: 7zStream.cc:35
SecToLook_Read
static SRes SecToLook_Read(void *pp, void *buf, size_t *size)
Definition: 7zStream.cc:127
LookInStream_SeekTo
SRes LookInStream_SeekTo(ILookInStream *stream, UInt64 offset)
Definition: 7zStream.cc:30
SecToLook_CreateVTable
void SecToLook_CreateVTable(CSecToLook *p)
Definition: 7zStream.cc:132
CSecToLook
Definition: Types.h:195
ESzSeek
ESzSeek
Definition: Types.h:155
ISeqInStream
Definition: Types.h:138
OrderedSet.t
t
Definition: OrderedSet.py:90
Int64
long long int Int64
Definition: Types.h:87
LookInStream_Read
SRes LookInStream_Read(ILookInStream *stream, void *buf, size_t size)
Definition: 7zStream.cc:56
LookToRead_Seek
static SRes LookToRead_Seek(void *pp, Int64 *pos, ESzSeek origin)
Definition: 7zStream.cc:112
SeqInStream_Read
SRes SeqInStream_Read(ISeqInStream *stream, void *buf, size_t size)
Definition: 7zStream.cc:20
LookToRead_Look_Lookahead
static SRes LookToRead_Look_Lookahead(void *pp, const void **buf, size_t *size)
Definition: 7zStream.cc:60
SZ_SEEK_SET
Definition: Types.h:155
SRes
int SRes
Definition: Types.h:43
LookToRead_BUF_SIZE
#define LookToRead_BUF_SIZE
Definition: Types.h:182
res
Definition: Electron.h:6
visDQMUpload.buf
buf
Definition: visDQMUpload.py:154
SeqInStream_ReadByte
SRes SeqInStream_ReadByte(ISeqInStream *stream, Byte *buf)
Definition: 7zStream.cc:24
LookToRead_Look_Exact
static SRes LookToRead_Look_Exact(void *pp, const void **buf, size_t *size)
Definition: 7zStream.cc:76
LookToRead_Init
void LookToRead_Init(CLookToRead *p)
Definition: 7zStream.cc:125
SecToRead_Read
static SRes SecToRead_Read(void *pp, void *buf, size_t *size)
Definition: 7zStream.cc:134
Types.h
createTree.pp
pp
Definition: createTree.py:17
LookToRead_Skip
static SRes LookToRead_Skip(void *pp, size_t offset)
Definition: 7zStream.cc:93
hltrates_dqm_sourceclient-live_cfg.offset
offset
Definition: hltrates_dqm_sourceclient-live_cfg.py:78
LookToRead_Read
static SRes LookToRead_Read(void *pp, void *buf, size_t *size)
Definition: 7zStream.cc:99
SZ_ERROR_INPUT_EOF
#define SZ_ERROR_INPUT_EOF
Definition: Types.h:32
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443
RINOK
#define RINOK(x)
Definition: Types.h:52