@@ -53,6 +53,22 @@ type FileWriterOptions struct {
5353 FlushGovernor block.FlushGovernor
5454}
5555
56+ func (o * FileWriterOptions ) ensureDefaults () {
57+ if o .Compression <= block .DefaultCompression || o .Compression >= block .NCompression {
58+ o .Compression = block .SnappyCompression
59+ }
60+ if o .ChecksumType == block .ChecksumTypeNone {
61+ o .ChecksumType = block .ChecksumTypeCRC32c
62+ }
63+ if o .FlushGovernor == (block.FlushGovernor {}) {
64+ o .FlushGovernor = block .MakeFlushGovernor (
65+ base .DefaultBlockSize ,
66+ base .DefaultBlockSizeThreshold ,
67+ base .SizeClassAwareBlockSizeThreshold ,
68+ nil )
69+ }
70+ }
71+
5672// FileWriterStats aggregates statistics about a blob file written by a
5773// FileWriter.
5874type FileWriterStats struct {
@@ -107,6 +123,7 @@ type compressedBlock struct {
107123
108124// NewFileWriter creates a new FileWriter.
109125func NewFileWriter (fn base.DiskFileNum , w objstorage.Writable , opts FileWriterOptions ) * FileWriter {
126+ opts .ensureDefaults ()
110127 fw := writerPool .Get ().(* FileWriter )
111128 fw .fileNum = fn
112129 fw .w = w
@@ -200,6 +217,9 @@ func (w *FileWriter) Close() (FileWriterStats, error) {
200217 panic (errors .AssertionFailedf ("block count mismatch: %d vs %d" ,
201218 stats .BlockCount , len (w .blockOffsets )))
202219 }
220+ if stats .BlockCount == 0 {
221+ panic (errors .AssertionFailedf ("no blocks written" ))
222+ }
203223
204224 // Write the index block.
205225 vbih := valblk.IndexHandle {
0 commit comments