Skip to content

Commit

Permalink
Make compressedWriter inactive as possible
Browse files Browse the repository at this point in the history
  • Loading branch information
anacrolix committed Oct 23, 2024
1 parent 2e9a01b commit 5fc835a
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions go/mcap/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ type Writer struct {
buf []byte
msg []byte
uncompressed bytes.Buffer
compressed *bytes.Buffer
compressedWriter *countingCRCWriter

currentChunkStartTime uint64
Expand Down Expand Up @@ -416,7 +415,7 @@ func (w *Writer) WriteDataEnd(e *DataEnd) error {
}

func (w *Writer) uncompressedSize() int {
panicif.NotEq(w.compressedWriter.Size(), int64(w.uncompressed.Len()))
//panicif.NotEq(w.compressedWriter.Size(), int64(w.uncompressed.Len()))
return w.uncompressed.Len()
}

Expand All @@ -425,17 +424,12 @@ func (w *Writer) flushActiveChunk() error {
return nil
}

err := w.compressedWriter.Close()
panicif.Err(err)

var c1 bytes.Buffer
cw, err := w.newCompressedWriter(&c1)
panicif.Err(err)
cw.Write(w.uncompressed.Bytes())
crc := cw.CRC()
panicif.NotEq(cw.CRC(), w.compressedWriter.CRC())
cw.Close()
panicif.NotEq(c1.Len(), w.compressed.Len())
compressedLen := c1.Len()

uncompressedLen := w.uncompressedSize()
Expand Down Expand Up @@ -474,10 +468,7 @@ func (w *Writer) flushActiveChunk() error {
if err != nil {
return err
}
w.compressed.Reset()
w.compressedWriter.Reset(w.compressed)
w.compressedWriter.ResetSize()
w.compressedWriter.ResetCRC()
cw.Reset(io.Discard)
w.uncompressed.Reset()
chunkEndOffset := w.w.Size()

Expand Down Expand Up @@ -922,7 +913,6 @@ func NewWriter(w io.Writer, opts *WriterOptions) (ret *Writer, err error) {
channels: make(map[uint16]*Channel),
schemas: make(map[uint16]*Schema),
messageIndexes: make(map[uint16]*MessageIndex),
compressed: new(bytes.Buffer),
currentChunkStartTime: math.MaxUint64,
currentChunkEndTime: 0,
currentChunkMessageCount: 0,
Expand All @@ -933,11 +923,14 @@ func NewWriter(w io.Writer, opts *WriterOptions) (ret *Writer, err error) {
},
opts: opts,
}
ret.compressedWriter, err = ret.newCompressedWriter(ret.compressed)
ret.compressedWriter, err = ret.newCompressedWriter(nil)
panicif.Err(err)
return ret, nil
}

func (w *Writer) uncompressedWriter() io.Writer {
return io.MultiWriter(&w.uncompressed, w.compressedWriter)
return &w.uncompressed
//return io.MultiWriter(&w.uncompressed, w.compressedWriter)
}

const checkWriter = false

0 comments on commit 5fc835a

Please sign in to comment.