GoSBHPF/SBHPFv1/streamed_serializer.go
zervo 96f0b64a11 Add SeekableBuffer
Add a specialised bytes.Buffer variant with seeking capabilities. This allows writers without seeking support to serialize using NodeSerializerStreamed.
2025-02-14 12:04:04 +01:00

20 lines
559 B
Go

package sbhpfv1
import (
"io"
"git.zervo.org/FLUX/GoSBHPF/pkg/seekablebuffer"
)
// SerializeNodeStream serializes a node object into a SBHPF node.
// It is a wrapper around SerializeNode that temporarily stores the serialized nodes in a seekable memory buffer.
// This is less efficient, but provides compatibility with writers that lack seeking support.
func SerializeNodeStream(w io.Writer, node *Node) error {
buf := &seekablebuffer.Buffer{}
if err := SerializeNode(buf, node); err != nil {
return err
}
_, err := io.Copy(w, buf)
return err
}