MCPcopy
hub / github.com/klauspost/compress / reset

Method reset

zstd/blockdec.go:128–212  ·  view source on GitHub ↗

reset will reset the block. Input must be a start of a block and will be at the end of the block when returned.

(br byteBuffer, windowSize uint64)

Source from the content-addressed store, hash-verified

126// reset will reset the block.
127// Input must be a start of a block and will be at the end of the block when returned.
128func (b *blockDec) reset(br byteBuffer, windowSize uint64) error {
129 b.WindowSize = windowSize
130 tmp, err := br.readSmall(3)
131 if err != nil {
132 println("Reading block header:", err)
133 return err
134 }
135 bh := uint32(tmp[0]) | (uint32(tmp[1]) << 8) | (uint32(tmp[2]) << 16)
136 b.Last = bh&1 != 0
137 b.Type = blockType((bh >> 1) & 3)
138 // find size.
139 cSize := int(bh >> 3)
140 maxSize := maxCompressedBlockSizeAlloc
141 switch b.Type {
142 case blockTypeReserved:
143 return ErrReservedBlockType
144 case blockTypeRLE:
145 if cSize > maxCompressedBlockSize || cSize > int(b.WindowSize) {
146 if debugDecoder {
147 printf("rle block too big: csize:%d block: %+v\n", uint64(cSize), b)
148 }
149 return ErrWindowSizeExceeded
150 }
151 b.RLESize = uint32(cSize)
152 if b.lowMem {
153 maxSize = cSize
154 }
155 cSize = 1
156 case blockTypeCompressed:
157 if debugDecoder {
158 println("Data size on stream:", cSize)
159 }
160 b.RLESize = 0
161 maxSize = maxCompressedBlockSizeAlloc
162 if windowSize < maxCompressedBlockSize && b.lowMem {
163 maxSize = int(windowSize) + compressedBlockOverAlloc
164 }
165 if cSize > maxCompressedBlockSize || uint64(cSize) > b.WindowSize {
166 if debugDecoder {
167 printf("compressed block too big: csize:%d block: %+v\n", uint64(cSize), b)
168 }
169 return ErrCompressedSizeTooBig
170 }
171 // Empty compressed blocks must at least be 2 bytes
172 // for Literals_Block_Type and one for Sequences_Section_Header.
173 if cSize < 2 {
174 return ErrBlockTooSmall
175 }
176 case blockTypeRaw:
177 if cSize > maxCompressedBlockSize || cSize > int(b.WindowSize) {
178 if debugDecoder {
179 printf("rle block too big: csize:%d block: %+v\n", uint64(cSize), b)
180 }
181 return ErrWindowSizeExceeded
182 }
183
184 b.RLESize = 0
185 // We do not need a destination for raw blocks.

Callers

nothing calls this directly

Calls 5

printlnFunction · 0.85
blockTypeTypeAlias · 0.85
printfFunction · 0.85
readSmallMethod · 0.65
readBigMethod · 0.65

Tested by

no test coverage detected