MCPcopy Index your code
hub / github.com/klauspost/compress / writeBlocks

Method writeBlocks

zstd/encoder.go:249–281  ·  view source on GitHub ↗
(p []byte)

Source from the content-addressed store, hash-verified

247}
248
249func (e *Encoder) writeBlocks(p []byte) (n int, err error) {
250 s := &e.state
251 for len(p) > 0 {
252 if len(p)+len(s.filling) < e.o.blockSize {
253 if e.o.crc {
254 _, _ = s.encoder.CRC().Write(p)
255 }
256 s.filling = append(s.filling, p...)
257 return n + len(p), nil
258 }
259 add := p
260 if len(p)+len(s.filling) > e.o.blockSize {
261 add = add[:e.o.blockSize-len(s.filling)]
262 }
263 if e.o.crc {
264 _, _ = s.encoder.CRC().Write(add)
265 }
266 s.filling = append(s.filling, add...)
267 p = p[len(add):]
268 n += len(add)
269 if len(s.filling) < e.o.blockSize {
270 return n, nil
271 }
272 err := e.nextBlock(false)
273 if err != nil {
274 return n, err
275 }
276 if debugAsserts && len(s.filling) > 0 {
277 panic(len(s.filling))
278 }
279 }
280 return n, nil
281}
282
283// nextBlock will synchronize and start compressing input in e.state.filling.
284// If an error has occurred during encoding it will be returned.

Callers 1

WriteMethod · 0.95

Calls 3

nextBlockMethod · 0.95
WriteMethod · 0.65
CRCMethod · 0.65

Tested by

no test coverage detected