Compare commits
4 commits
Author | SHA1 | Date | |
---|---|---|---|
3b9127c641 | |||
72d062ac0d | |||
a05d2cae18 | |||
1ad74669d6 |
4 changed files with 21 additions and 6 deletions
2
.gitattributes
vendored
Normal file
2
.gitattributes
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
tests/index.html -linguist-detectable
|
||||
tests/index.html linguist-vendored
|
|
@ -1,7 +1,8 @@
|
|||
# jsStreams
|
||||
|
||||
Go library to communicate with the JS Stream API by bridging the JS ReadableStream object to a Go io.ReaderCloser.
|
||||
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.
|
||||
It also works vice versa, and with pipe readers/writers.
|
||||
|
||||
[](https://goreportcard.com/report/git.ailur.dev/ailur/jsStreams) [](https://pkg.go.dev/git.ailur.dev/ailur/jsStreams)
|
||||
|
||||
The API is pretty self-explanatory - it provides a function to create an io.ReaderCloser from a JS ReadableStream object.
|
||||
The API is pretty self-explanatory, see the Go Reference badge above for the full documentation.
|
12
main.go
12
main.go
|
@ -67,8 +67,10 @@ func (r *ReadableStream) Close() (err error) {
|
|||
defer func() {
|
||||
// We don't want any errors to be thrown if the stream is already closed.
|
||||
recovery := recover()
|
||||
if !strings.Contains(recovery.(string), "Can not close stream after closing or error") {
|
||||
err = fmt.Errorf("panic: %v", recovery)
|
||||
if !strings.Contains(fmt.Sprint(recovery), "Can not close stream after closing or error") {
|
||||
if recovery != nil {
|
||||
err = fmt.Errorf("panic: %v", recovery)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
|
@ -141,8 +143,10 @@ func (w *WritableStream) Close() (err error) {
|
|||
defer func() {
|
||||
// We don't want any errors to be thrown if the stream is already closed.
|
||||
recovery := recover()
|
||||
if !strings.Contains(recovery.(string), "Can not close stream after closing or error") {
|
||||
err = fmt.Errorf("panic: %v", recovery)
|
||||
if !strings.Contains(fmt.Sprint(recovery), "Can not close stream after closing or error") {
|
||||
if recovery != nil {
|
||||
err = fmt.Errorf("panic: %v", recovery)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
|
|
|
@ -21,6 +21,10 @@ func main() {
|
|||
return
|
||||
}
|
||||
fmt.Println(string(buffer))
|
||||
err = readStream.Close()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
}()
|
||||
|
||||
return nil
|
||||
|
@ -34,6 +38,10 @@ func main() {
|
|||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
err = writeStream.Close()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
}()
|
||||
|
||||
return nil
|
||||
|
|
Loading…
Add table
Reference in a new issue