Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions internal/jsutil/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,20 @@ func ConvertReadableStreamToReadCloser(stream js.Value) io.ReadCloser {
// - ReadableStream: https://developer.mozilla.org/docs/Web/API/ReadableStream
// - This implementation is based on: https://deno.land/std@0.139.0/streams/conversion.ts#L230
type readerToReadableStream struct {
reader io.ReadCloser
chunkBuf []byte
initialized bool
reader io.ReadCloser
chunkBuf []byte
}

// Pull implements ReadableStream's pull method.
// - https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream/ReadableStream#pull
func (rs *readerToReadableStream) Pull(controller js.Value) error {
if !rs.initialized {
ua := NewUint8Array(0)
controller.Call("enqueue", ua)
rs.initialized = true
return nil
}
n, err := rs.reader.Read(rs.chunkBuf)
if n != 0 {
ua := NewUint8Array(n)
Expand Down
Loading