mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-19 00:38:14 +01:00
Add a rac.CodecWriter.CanCut method
This commit is contained in:
1 parent
0a31851d85
commit
1fa39758cf
3 files changed
+14
No files matched your search
@@ -64,6 +64,8 @@ const (
|
||||
var indexLocationAtEndMagic = []byte("\x72\xC3\x63\x00")
|
||||
|
||||
var (
|
||||
ErrCodecWriterDoesNotSupportCChunkSize = errors.New("rac: CodecWriter does not support CChunkSize")
|
||||
|
||||
errAlreadyClosed = errors.New("rac: already closed")
|
||||
errCChunkSizeIsTooSmall = errors.New("rac: CChunkSize is too small")
|
||||
errILAEndTempFile = errors.New("rac: IndexLocationAtEnd requires a nil TempFile")
|
||||
|
||||
@@ -179,6 +179,9 @@ type CodecWriter interface {
|
||||
Compress(p []byte, q []byte, resourcesData [][]byte) (
|
||||
codec Codec, compressed []byte, secondaryResource int, tertiaryResource int, retErr error)
|
||||
|
||||
// CanCut returns whether the CodecWriter supports the optional Cut method.
|
||||
CanCut() bool
|
||||
|
||||
// Cut modifies encoded's contents such that encoded[:encodedLen] is valid
|
||||
// codec-compressed data, assuming that encoded starts off containing valid
|
||||
// codec-compressed data.
|
||||
@@ -351,6 +354,10 @@ func (w *Writer) initialize() error {
|
||||
if w.DChunkSize > 0 {
|
||||
w.dChunkSize = w.DChunkSize
|
||||
} else if w.CChunkSize > 0 {
|
||||
if !w.CodecWriter.CanCut() {
|
||||
w.err = ErrCodecWriterDoesNotSupportCChunkSize
|
||||
return w.err
|
||||
}
|
||||
w.cChunkSize = w.CChunkSize
|
||||
if w.cChunkSize > maxCChunkSize {
|
||||
w.cChunkSize = maxCChunkSize
|
||||
|
||||
@@ -264,6 +264,11 @@ func (w *CodecWriter) compress(p []byte, q []byte, dict []byte) ([]byte, error)
|
||||
return w.compressed.Bytes(), nil
|
||||
}
|
||||
|
||||
// CanCut implements rac.CodecWriter.
|
||||
func (w *CodecWriter) CanCut() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// Cut implements rac.CodecWriter.
|
||||
func (w *CodecWriter) Cut(codec rac.Codec, encoded []byte, maxEncodedLen int) (encodedLen int, decodedLen int, retErr error) {
|
||||
if codec != rac.CodecZlib {
|
||||
|
||||
Reference in new issue
Block a user