crc32block

package
v3.5.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 3, 2025 License: Apache-2.0, Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// write crc after payload
	ModeEncode uint8 = 1 // encode mode
	ModeAppend uint8 = 2 // append, append buffer to stable, just fix first block
	ModeCheck  uint8 = 3 // check, return buffer with head, crc and tail
	ModeDecode uint8 = 4 // decode, return data buffer
	ModeLoad   uint8 = 5 // load, return buffer with head, should with section
	ModeFix    uint8 = 6 // fix, return buffer with fixed first and last block crc

	// write crc before payload
	ModeBlockEncode uint8 = 11 // encode mode, crc at head of block
	ModeBlockDecode uint8 = 12 // decode, return buffer with crc size and head

)

Variables

View Source
var (
	ErrInvalidBlock  = errors.New("crc32block: invalid block buffer")
	ErrMismatchedCrc = errors.New("crc32block: mismatched checksum")
	ErrReadOnClosed  = errors.New("crc32block: read on closed")
)
View Source
var ErrFrameContinue = transport.ErrFrameContinue

Functions

func BlockPayload

func BlockPayload(blockLen int64) int64

func ConstZeroCrc

func ConstZeroCrc(size int) uint32

func DecodeSize

func DecodeSize(totalSize int64, blockLen int64) int64

func DecodeSizeWithDefualtBlock

func DecodeSizeWithDefualtBlock(size int64) int64

func EncodeSize

func EncodeSize(size int64, blockLen int64) int64

func EncodeSizeWithDefualtBlock

func EncodeSizeWithDefualtBlock(size int64) int64

func IsZeroBuffer

func IsZeroBuffer(buffer []byte) bool

func NewBlockReader

func NewBlockReader(r io.Reader, limit int64, block []byte) *blockReader

func NewDecoderReader deprecated

func NewDecoderReader(in io.Reader) io.Reader

NewDecoderReader returns io.Reader

Deprecated: no reused buffer, use NewBodyDecoder to instead.

func NewEncoderReader deprecated

func NewEncoderReader(r io.Reader) io.Reader

NewEncoderReader returns io.Reader

Deprecated: no reused buffer, use NewBodyEncoder to instead.

func NewLimitEncoderReader

func NewLimitEncoderReader(r io.Reader, limitSize int64) (enc *limitEncoderReader)

func NewPartialDecoder

func NewPartialDecoder(rc io.ReadCloser, actualSize, stableSize int64) io.ReadCloser

NewPartialDecoder returns partial crc32 decoder.

func NewPartialEncoder

func NewPartialEncoder(rc io.ReadCloser, actualSize, stableSize int64) io.ReadCloser

NewPartialEncoder returns partial crc32 encoder, added the padding buffer, actual size is next content size, stable size was written content size.

func NewSizedAppend

func NewSizedAppend(rc io.ReadCloser,
	actualSize, stableSize, blockSize int64, section bool,
	lastpad, lastcrc []byte,
) (io.ReadCloser, error)

NewSizedAppend returns sized alignment crc32 append encoder.

func NewSizedBlockDecoder

func NewSizedBlockDecoder(rc io.ReadCloser, actualSize, blockSize int64) io.ReadCloser

NewSizedBlockDecoder return block sized decoder.

func NewSizedBlockEncoder

func NewSizedBlockEncoder(rc io.ReadCloser, actualSize, blockSize int64) io.ReadCloser

NewSizedBlockEncoder return block sized encoder.

func NewSizedCoder

func NewSizedCoder(rc io.ReadCloser, actualSize, stableSize, blockSize int64, mode uint8, section bool) io.ReadCloser

NewSizedCoder returns sized alignment crc32 en-decoder.

func NewSizedDecoder

func NewSizedDecoder(rc io.ReadCloser, actualSize int64) io.ReadCloser

NewSizedDecoder returns sized crc32 decoder.

func NewSizedEncoder

func NewSizedEncoder(rc io.ReadCloser, actualSize int64) io.ReadCloser

NewSizedEncoder returns sized crc32 encoder.

func NewSizedFixer

func NewSizedFixer(rc io.ReadCloser, actualSize, from, to, blockSize int64) (int64, int64, io.ReadCloser)

NewSizedFixer returns fixed-range crc32 data, [from, to). The from should be in the first block of reader. Only fix the first and last block if needed, do not check other blocks. Returns head and tail are aligned.

func NewSizedRangeBlockDecoder

func NewSizedRangeBlockDecoder(rc io.ReadCloser, actualSize, from, to, blockSize int64) (int64, int64, io.ReadCloser)

NewSizedRangeBlockDecoder returns ranged crc32 block decoder, [from, to). The from should be in the first block of reader.

func NewSizedRangeDecoder

func NewSizedRangeDecoder(rc io.ReadCloser, actualSize, from, to, blockSize int64) (int64, int64, io.ReadCloser)

NewSizedRangeDecoder returns ranged crc32 decoder, [from, to). The from should be in the first block of reader.

func NewSizedSectionDecoder

func NewSizedSectionDecoder(rc io.ReadCloser, actualSize int64) io.ReadCloser

NewSizedSectionDecoder returns section crc32 decoder.

func PartialDecodeSize

func PartialDecodeSize(totalSize, tail, stableSize int64) int64

func PartialDecodeSizeWith

func PartialDecodeSizeWith(totalSize, tail, stableSize, blockLen int64) int64

func PartialEncodeSize

func PartialEncodeSize(actualSize, stableSize int64) (int64, int64)

func PartialEncodeSizeWith

func PartialEncodeSizeWith(actualSize, stableSize, blockLen int64) (int64, int64)

func SetBlockSize

func SetBlockSize(blockSize int64)

SetBlockSize set default block size

Types

type Decoder

type Decoder struct {
	// contains filtered or unexported fields
}

func NewDecoder

func NewDecoder(r io.ReaderAt, off int64, size int64) (dec *Decoder, err error)

func NewDecoderWithBlock

func NewDecoderWithBlock(r io.ReaderAt, off int64, size int64, block []byte, bufferSize int64) (dec *Decoder, err error)

func (*Decoder) Reader

func (dec *Decoder) Reader(from, to int64) (r io.Reader, err error)

type Encoder

type Encoder struct {
	// contains filtered or unexported fields
}

func NewEncoder

func NewEncoder(block []byte) (enc *Encoder, err error)

func (*Encoder) Encode

func (enc *Encoder) Encode(from io.Reader, limitSize int64, to io.Writer) (n int64, err error)

type ReaderError

type ReaderError struct {
	// contains filtered or unexported fields
}

type RequestBody

type RequestBody interface {
	io.ReadCloser

	// CodeSize returns encoded whole body size for encoding,
	// or origin body size for decoding.
	CodeSize(int64) int64
}

RequestBody is implemented http request's body. always io.ReadCloser.

For client requests, The HTTP Client's Transport is responsible for calling the Close method. Necessarily call the Close method if the body's life-cycle control by yourself.

For server requests, the Server will close the request body. The ServeHTTP Handler does not need to.

The Body must allow Read to be called concurrently with Close. In particular, calling Close should unblock a Read waiting for input.

func NewBodyDecoder

func NewBodyDecoder(rc io.ReadCloser) RequestBody

NewBodyDecoder returns decoder with crc32.

If rc == nil, the decoder is called just with CodeSize, you need not to Close it at all.

func NewBodyEncoder

func NewBodyEncoder(rc io.ReadCloser) RequestBody

NewBodyEncoder returns encoder with crc32.

If rc == nil, the encoder is called just with CodeSize, you need not to Close it at all.

type WriterError

type WriterError struct {
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL