From 64f97e7cff037a77ec275139b4a6f1e2f3970551 Mon Sep 17 00:00:00 2001
From: a
Date: Thu, 26 Oct 2023 05:20:54 -0500
Subject: [PATCH 1/3] allow weir dstreaming
---
w.go | 16 +++++++++++++++-
w_stream.go | 1 -
2 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/w.go b/w.go
index 005a39a..b0370b4 100644
--- a/w.go
+++ b/w.go
@@ -16,7 +16,10 @@ type Writer struct {
// Write implements io.Writer.
func (w *Writer) Write(p []byte) (n int, err error) {
if w.stream != nil {
- return 0, errStreaming
+ if len(w.Buf) > 0 {
+ w.Flush()
+ }
+ return w.stream.writer.Write(p)
}
w.Buf = append(w.Buf, p...)
return len(p), nil
@@ -63,6 +66,17 @@ func (w *Writer) Grow(n int) {
w.Buf = buf.Bytes()
}
+// flush flushes the stream
+func (w *Writer) Flush() (fail bool) {
+ if w.stream != nil {
+ w.Buf, fail = w.stream.flush(w.Buf)
+ if fail {
+ return true
+ }
+ }
+ return false
+}
+
// byte writes a single byte.
func (w *Writer) byte(c byte) (fail bool) {
if w.stream == nil {
diff --git a/w_stream.go b/w_stream.go
index 0ad90b0..9a6c536 100644
--- a/w_stream.go
+++ b/w_stream.go
@@ -94,7 +94,6 @@ func writeStreamByteseqSlow[S byteseq.Byteseq](w *Writer, s S) bool {
if fail {
return true
}
-
n := copy(w.Buf[len(w.Buf):cap(w.Buf)], s)
s = s[n:]
w.Buf = w.Buf[:len(w.Buf)+n]
From dca920e2924fea08f9611bc48c62f4dd5ac15b30 Mon Sep 17 00:00:00 2001
From: a
Date: Thu, 26 Oct 2023 05:23:56 -0500
Subject: [PATCH 2/3] better error
---
w.go | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/w.go b/w.go
index b0370b4..65eb3f1 100644
--- a/w.go
+++ b/w.go
@@ -17,7 +17,9 @@ type Writer struct {
func (w *Writer) Write(p []byte) (n int, err error) {
if w.stream != nil {
if len(w.Buf) > 0 {
- w.Flush()
+ if w.Flush() {
+ return 0, w.stream.writeErr
+ }
}
return w.stream.writer.Write(p)
}
From 25d63720ace6643fd778c3066f4f4f74bc47f0fc Mon Sep 17 00:00:00 2001
From: a
Date: Thu, 26 Oct 2023 11:37:58 -0500
Subject: [PATCH 3/3] Update w.go
---
w.go | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/w.go b/w.go
index 65eb3f1..94ae564 100644
--- a/w.go
+++ b/w.go
@@ -68,7 +68,7 @@ func (w *Writer) Grow(n int) {
w.Buf = buf.Bytes()
}
-// flush flushes the stream
+// Flush flushes the stream. It does nothing if not in streaming mode
func (w *Writer) Flush() (fail bool) {
if w.stream != nil {
w.Buf, fail = w.stream.flush(w.Buf)