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

Method encodeAll

zstd/encoder.go:731–839  ·  view source on GitHub ↗
(enc encoder, src, dst []byte)

Source from the content-addressed store, hash-verified

729}
730
731func (e *Encoder) encodeAll(enc encoder, src, dst []byte) []byte {
732 if len(src) == 0 {
733 if e.o.fullZero {
734 // Add frame header.
735 fh := frameHeader{
736 ContentSize: 0,
737 WindowSize: MinWindowSize,
738 SingleSegment: true,
739 // Adding a checksum would be a waste of space.
740 Checksum: false,
741 DictID: 0,
742 }
743 dst = fh.appendTo(dst)
744
745 // Write raw block as last one only.
746 var blk blockHeader
747 blk.setSize(0)
748 blk.setType(blockTypeRaw)
749 blk.setLast(true)
750 dst = blk.appendTo(dst)
751 }
752 return dst
753 }
754
755 // Use single segments when above minimum window and below window size.
756 single := len(src) <= e.o.windowSize && len(src) > MinWindowSize
757 if e.o.single != nil {
758 single = *e.o.single
759 }
760 fh := frameHeader{
761 ContentSize: uint64(len(src)),
762 WindowSize: uint32(enc.WindowSize(int64(len(src)))),
763 SingleSegment: single,
764 Checksum: e.o.crc,
765 DictID: e.o.dict.ID(),
766 }
767
768 // If less than 1MB, allocate a buffer up front.
769 if len(dst) == 0 && cap(dst) == 0 && len(src) < 1<<20 && !e.o.lowMem {
770 dst = make([]byte, 0, len(src))
771 }
772 dst = fh.appendTo(dst)
773
774 // If we can do everything in one block, prefer that.
775 if len(src) <= e.o.blockSize {
776 enc.Reset(e.o.dict, true)
777 // Slightly faster with no history and everything in one block.
778 if e.o.crc {
779 _, _ = enc.CRC().Write(src)
780 }
781 blk := enc.Block()
782 blk.last = true
783 if e.o.dict == nil {
784 enc.EncodeNoHist(blk, src)
785 } else {
786 enc.Encode(blk, src)
787 }
788

Callers 3

dispatchJobMethod · 0.95
nextBlockMethod · 0.95
EncodeAllMethod · 0.95

Calls 15

appendToMethod · 0.95
setSizeMethod · 0.95
setTypeMethod · 0.95
setLastMethod · 0.95
appendToMethod · 0.95
IDMethod · 0.80
pushOffsetsMethod · 0.80
calcSkippableFrameFunction · 0.70
skippableFrameFunction · 0.70
WindowSizeMethod · 0.65
ResetMethod · 0.65
WriteMethod · 0.65

Tested by

no test coverage detected