Documentation ¶
Overview ¶
Package ioutil contains extensions and utilities for package io from the standard library.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type LimitError ¶
type LimitError struct { // Limit is the limit that triggered the error. Limit uint64 }
LimitError is returned when the Limit is reached.
func (*LimitError) Error ¶
func (err *LimitError) Error() (msg string)
Error implements the error interface for *LimitError.
type TruncatedWriter ¶ added in v0.20.2
type TruncatedWriter struct {
// contains filtered or unexported fields
}
TruncatedWriter is an io.Writer that writes up to a certain limit of bytes to its underlying writer and then ignores the rest.
Example ¶
package main import ( "bytes" "fmt" "github.com/AdguardTeam/golibs/ioutil" ) func main() { data := []byte("hello") buf := &bytes.Buffer{} fmt.Println(ioutil.NewTruncatedWriter(buf, 1).Write(data)) fmt.Println(buf) buf = &bytes.Buffer{} fmt.Println(ioutil.NewTruncatedWriter(buf, 2).Write(data)) fmt.Println(buf) buf = &bytes.Buffer{} fmt.Println(ioutil.NewTruncatedWriter(buf, 10).Write(data)) fmt.Println(buf) }
Output: 5 <nil> h 5 <nil> he 5 <nil> hello
func NewTruncatedWriter ¶ added in v0.20.2
func NewTruncatedWriter(w io.Writer, limit uint) (tw *TruncatedWriter)
NewTruncatedWriter returns a new truncated writer. It wraps the given writer w the way it writes up to the given limit and then ignores the rest.
Click to show internal directories.
Click to hide internal directories.