diff --git a/internal/jsutil/stream.go b/internal/jsutil/stream.go index dc8afc92..9c3439ef 100644 --- a/internal/jsutil/stream.go +++ b/internal/jsutil/stream.go @@ -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)