diff --git a/snapshot.go b/snapshot.go index 61cb62b..d475e7b 100644 --- a/snapshot.go +++ b/snapshot.go @@ -41,11 +41,6 @@ func (c *Collection) WriteTo(dst io.Writer) (int64, error) { c.lock.Lock() defer c.lock.Unlock() - // Check if there's any data to write - if c.fill.Count() == 0 { - return 0, fmt.Errorf("column: unable to write an empty collection") - } - // Create a writer, encoder and a reusable buffer encoder := c.codec.EncoderFor(dst) writer := iostream.NewWriter(c.codec.EncoderFor(dst)) diff --git a/snapshot_test.go b/snapshot_test.go index da5e17a..73283be 100644 --- a/snapshot_test.go +++ b/snapshot_test.go @@ -225,11 +225,23 @@ func TestWriteToFailures(t *testing.T) { } } -func TestWriteToEmpty(t *testing.T) { - input := NewCollection() - input.CreateColumn("name", ForString()) - _, err := input.WriteTo(bytes.NewBuffer(nil)) - assert.Error(t, err) +func TestWriteEmpty(t *testing.T) { + buffer := bytes.NewBuffer(nil) + + { // Write the collection + input := NewCollection() + input.CreateColumn("name", ForString()) + _, err := input.WriteTo(buffer) + assert.NoError(t, err) + } + + { // Read the collection back + output := NewCollection() + output.CreateColumn("name", ForString()) + _, err := output.ReadFrom(buffer) + assert.NoError(t, err) + assert.Equal(t, 0, output.Count()) + } } func TestReadFromFailures(t *testing.T) {