diff --git a/lib/rac/rac.go b/lib/rac/rac.go index 79d2fc1f..8933ced8 100644 --- a/lib/rac/rac.go +++ b/lib/rac/rac.go @@ -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") diff --git a/lib/rac/writer.go b/lib/rac/writer.go index 00cf89a0..172e1fc8 100644 --- a/lib/rac/writer.go +++ b/lib/rac/writer.go @@ -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 diff --git a/lib/raczlib/raczlib.go b/lib/raczlib/raczlib.go index 9438de29..a47874f8 100644 --- a/lib/raczlib/raczlib.go +++ b/lib/raczlib/raczlib.go @@ -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 {