Add a rac.CodecWriter.CanCut method
diff --git a/lib/rac/rac.go b/lib/rac/rac.go
index 79d2fc1..8933ced 100644
--- a/lib/rac/rac.go
+++ b/lib/rac/rac.go
@@ -64,6 +64,8 @@
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 00cf89a..172e1fc 100644
--- a/lib/rac/writer.go
+++ b/lib/rac/writer.go
@@ -179,6 +179,9 @@
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 @@
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 9438de2..a47874f 100644
--- a/lib/raczlib/raczlib.go
+++ b/lib/raczlib/raczlib.go
@@ -264,6 +264,11 @@
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 {