Skip to content

Commit

Permalink
add wav
Browse files Browse the repository at this point in the history
  • Loading branch information
zns committed Apr 28, 2023
1 parent e8d9762 commit d8d6297
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
32 changes: 32 additions & 0 deletions examples/gno.land/p/demo/wav/wav.gno
Original file line number Diff line number Diff line change
@@ -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
}
15 changes: 15 additions & 0 deletions examples/gno.land/p/demo/wav/wav_test.gno
Original file line number Diff line number Diff line change
@@ -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")
}
}

0 comments on commit d8d6297

Please sign in to comment.