Compare commits

..

No commits in common. "master" and "v1.2.0" have entirely different histories.

4 changed files with 6 additions and 21 deletions

2
.gitattributes vendored
View file

@ -1,2 +0,0 @@
tests/index.html -linguist-detectable
tests/index.html linguist-vendored

View file

@ -1,8 +1,7 @@
# jsStreams # jsStreams
Go library to communicate with the JS Stream API by bridging the JS ReadableStream and WritableStream objects to a Go io.ReaderCloser and io.WriterCloser. Go library to communicate with the JS Stream API by bridging the JS ReadableStream object to a Go io.ReaderCloser.
It also works vice versa, and with pipe readers/writers.
[![Go Report Card](https://goreportcard.com/badge/git.ailur.dev/ailur/jsStreams)](https://goreportcard.com/report/git.ailur.dev/ailur/jsStreams) [![Go Reference](https://pkg.go.dev/badge/git.ailur.dev/ailur/jsStreams.svg)](https://pkg.go.dev/git.ailur.dev/ailur/jsStreams) [![Go Report Card](https://goreportcard.com/badge/git.ailur.dev/ailur/jsStreams)](https://goreportcard.com/report/git.ailur.dev/ailur/jsStreams) [![Go Reference](https://pkg.go.dev/badge/git.ailur.dev/ailur/jsStreams.svg)](https://pkg.go.dev/git.ailur.dev/ailur/jsStreams)
The API is pretty self-explanatory, see the Go Reference badge above for the full documentation. The API is pretty self-explanatory - it provides a function to create an io.ReaderCloser from a JS ReadableStream object.

View file

@ -67,11 +67,9 @@ func (r *ReadableStream) Close() (err error) {
defer func() { defer func() {
// We don't want any errors to be thrown if the stream is already closed. // We don't want any errors to be thrown if the stream is already closed.
recovery := recover() recovery := recover()
if !strings.Contains(fmt.Sprint(recovery), "Can not close stream after closing or error") { if !strings.Contains(recovery.(string), "Can not close stream after closing or error") {
if recovery != nil {
err = fmt.Errorf("panic: %v", recovery) err = fmt.Errorf("panic: %v", recovery)
} }
}
}() }()
r.lock.Lock() r.lock.Lock()
@ -143,11 +141,9 @@ func (w *WritableStream) Close() (err error) {
defer func() { defer func() {
// We don't want any errors to be thrown if the stream is already closed. // We don't want any errors to be thrown if the stream is already closed.
recovery := recover() recovery := recover()
if !strings.Contains(fmt.Sprint(recovery), "Can not close stream after closing or error") { if !strings.Contains(recovery.(string), "Can not close stream after closing or error") {
if recovery != nil {
err = fmt.Errorf("panic: %v", recovery) err = fmt.Errorf("panic: %v", recovery)
} }
}
}() }()
w.lock.Lock() w.lock.Lock()

View file

@ -21,10 +21,6 @@ func main() {
return return
} }
fmt.Println(string(buffer)) fmt.Println(string(buffer))
err = readStream.Close()
if err != nil {
fmt.Println(err)
}
}() }()
return nil return nil
@ -38,10 +34,6 @@ func main() {
fmt.Println(err) fmt.Println(err)
return return
} }
err = writeStream.Close()
if err != nil {
fmt.Println(err)
}
}() }()
return nil return nil