Documentation
¶
Overview ¶
Package iobp provides useful implementations of interfaces defined in stdlib io package.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CountingSink ¶
type CountingSink int64
CountingSink is an io.Writer implementation that discards all incoming data but tracks how many bytes were "written".
This can be used as a sink for encoders or as an additional output via a MultiWriter to track data sizes without buffering all of the data in memory.
A Write to a CountingSink cannot fail. A CountingSink is not safe for concurrent use.
Example ¶
This example demonstrates how to use CountingSink to count the size of a json-serialized object.
package main
import (
"encoding/json"
"fmt"
"github.com/reddit/baseplate.go/iobp"
)
func main() {
// The json string would be "[0,1,2,3,4]\n", so the size should be 12.
object := []int{0, 1, 2, 3, 4}
var sink iobp.CountingSink
if err := json.NewEncoder(&sink).Encode(object); err != nil {
panic(err)
}
fmt.Printf("JSON size for %#v: %d\n", object, sink.Size())
}
Output: JSON size for []int{0, 1, 2, 3, 4}: 12
func (CountingSink) Size ¶
func (cs CountingSink) Size() int64
Size returns the current counted size.
Click to show internal directories.
Click to hide internal directories.