diff --git a/bytestream.go b/bytestream.go index 4459025b..6601a779 100644 --- a/bytestream.go +++ b/bytestream.go @@ -129,6 +129,11 @@ func ByteStreamProducer(opts ...byteStreamOpt) Producer { } if data != nil { + if str, ok := data.(string); ok { + _, err := writer.Write([]byte(str)) + return err + } + if e, ok := data.(error); ok { _, err := writer.Write([]byte(e.Error())) return err diff --git a/bytestream_test.go b/bytestream_test.go index 96d51aa1..358fc28e 100644 --- a/bytestream_test.go +++ b/bytestream_test.go @@ -84,6 +84,12 @@ func TestByteStreamProducer(t *testing.T) { rdr.Reset() } + // string can also be used to produce + if assert.NoError(t, cons.Produce(&rdr, expected)) { + assert.Equal(t, expected, rdr.String()) + rdr.Reset() + } + // binary slices can also be used to produce if assert.NoError(t, cons.Produce(&rdr, []byte(expected))) { assert.Equal(t, expected, rdr.String())