1 package wasm
2 3 import (
4 "io"
5 )
6 7 // reader wraps io.Reader and keeps track of the current position in the input.
8 type reader struct {
9 rd io.Reader // reader provided by the client
10 i int // current index
11 }
12 13 func newReader(r io.Reader) *reader {
14 return &reader{r, 0}
15 }
16 17 // Index returns the current position in the file.
18 func (r *reader) Index() int {
19 return r.i
20 }
21 22 // Read reads bytes into p and returns the number of bytes read.
23 // The number of bytes read are recorded in the reader.
24 func (r *reader) Read(p []byte) (int, error) {
25 n, err := r.rd.Read(p)
26 if err != nil {
27 return 0, err
28 }
29 r.i += n
30 return n, nil
31 }
32