From d8d62977cc702e8ffd9e831c3d2614fcbd8b5b73 Mon Sep 17 00:00:00 2001 From: zns Date: Fri, 28 Apr 2023 06:33:45 -0700 Subject: [PATCH] add wav --- examples/gno.land/p/demo/wav/wav.gno | 32 +++++++++++++++++++++++ examples/gno.land/p/demo/wav/wav_test.gno | 15 +++++++++++ 2 files changed, 47 insertions(+) create mode 100644 examples/gno.land/p/demo/wav/wav.gno create mode 100644 examples/gno.land/p/demo/wav/wav_test.gno diff --git a/examples/gno.land/p/demo/wav/wav.gno b/examples/gno.land/p/demo/wav/wav.gno new file mode 100644 index 00000000000..2447f6df9af --- /dev/null +++ b/examples/gno.land/p/demo/wav/wav.gno @@ -0,0 +1,32 @@ +package wav + +import ( + "encoding/binary" + "io" +) + +type Writer struct { + io.Writer +} + +type writeCallback func(w io.Writer) + +func NewWriter(w io.Writer, fileType []byte, fileSize uint32) *Writer { + w.Write([]byte("RIFF")) + binary.Write(w, binary.LittleEndian, fileSize) + w.Write(fileType) + return &Writer{w} +} + +func (w *Writer) WriteChunk(chunkID []byte, chunkSize uint32, cb writeCallback) (err error) { + _, err = w.Write(chunkID) + if err != nil { + return + } + err = binary.Write(w, binary.LittleEndian, chunkSize) + if err != nil { + return + } + cb(w) + return +} diff --git a/examples/gno.land/p/demo/wav/wav_test.gno b/examples/gno.land/p/demo/wav/wav_test.gno new file mode 100644 index 00000000000..d75d20a7fe7 --- /dev/null +++ b/examples/gno.land/p/demo/wav/wav_test.gno @@ -0,0 +1,15 @@ +package wav + +import ( + "bufio" + "bytes" + "testing" +) + +func TestWav(t *testing.T) { + var buf bytes.Buffer + w := NewWriter(bufio.NewWriter(&buf), []byte("wav"), 100) + if w == nil { + t.Errorf("could not make") + } +}