Documentation
¶
Overview ¶
Example (ByteSize) ¶
package main import ( "bytes" "io" "go.llib.dev/frameless/pkg/iokit" ) func main() { var bs = make([]byte, iokit.Megabyte) buf := &bytes.Buffer{} n, err := buf.Write(bs) if err != nil { panic(err.Error()) } if n < iokit.Kilobyte { // } io.LimitReader(buf, 128*iokit.Kibibyte) }
Output:
Index ¶
- Constants
- func FormatByteSize[ByteSize byteSize](n ByteSize) string
- func MoveByte(in ByteReader, out ByteWriter) (byte, error)
- func MoveRune(in RuneReader, out RuneWriter) (rune, int, error)
- func PeekByte(in bytePeeker) (byte, error)
- func PeekRune(in runePeeker) (rune, int, error)
- func ReadAllWithLimit(body io.Reader, readLimit ByteSize) (_ []byte, returnErr error)
- type Buffer
- type ByteReader
- type ByteSize
- type ByteUnreader
- type ByteWriter
- type KeepAliveReader
- type RuneReader
- type RuneUnreader
- type RuneWriter
- type StubReader
- type SyncReadWriter
- type SyncReader
- type SyncWriter
Examples ¶
Constants ¶
const ( Byte = 1 << (10 * iota) // ignore first value by assigning to blank identifier Kibibyte Mebibyte Gibibyte Tebibyte Pebibyte )
const ( Kilobyte = Kibibyte Megabyte = Mebibyte Gigabyte = Gibibyte Terabyte = Tebibyte )
const ErrReadLimitReached errorkit.Error = "request-entity-too-large"
const ErrSeekNegativePosition errorkit.Error = "iokit: negative position"
Variables ¶
This section is empty.
Functions ¶
func FormatByteSize ¶ added in v0.222.0
func FormatByteSize[ByteSize byteSize](n ByteSize) string
FormatByteSize will format byte size interpreted as the unit of digital information. Historically, the byte was the number of bits used to encode a single character of text in a computer and for this reason it is the smallest addressable unit of memory in many computer architectures
| Value | IEC | Memory | |-------|--------------|--------------| | 1 | B byte | B byte | | 1024 | KiB kibibyte | KB kilobyte | | 10242 | MiB mebibyte | MB megabyte | | 10243 | GiB gibibyte | GB gigabyte | | 10244 | TiB tebibyte | TB terabyte | | 10245 | PiB pebibyte | – | | 10246 | EiB exbibyte | – | | 10247 | ZiB zebibyte | – | | 10248 | YiB yobibyte | – |
func MoveByte ¶ added in v0.258.0
func MoveByte(in ByteReader, out ByteWriter) (byte, error)
func MoveRune ¶ added in v0.258.0
func MoveRune(in RuneReader, out RuneWriter) (rune, int, error)
Types ¶
type Buffer ¶
type Buffer struct {
// contains filtered or unexported fields
}
Buffer is an in-memory io.ReadWriteSeeker implementation
type ByteReader ¶ added in v0.258.0
type ByteUnreader ¶ added in v0.258.0
type ByteUnreader interface {
UnreadByte() error
}
type ByteWriter ¶ added in v0.258.0
type KeepAliveReader ¶ added in v0.218.2
type KeepAliveReader struct { Source io.Reader // | io.ReadCloser // IdleTimeout specifies how long the KeepAliveReader will wait without any read operations // before it reads from the Source to prevent an I/O timeout. IdleTimeout time.Duration // contains filtered or unexported fields }
KeepAliveReader is a decorator designed to help prevent read timeouts. When working with external readers in a streaming fashion, such as an `http.Request#Body`, regular reads are crucial to avoid IO closures due to read timeouts. For example, If processing a single stream element takes longer than the read timeout on the source server, the server might close the input stream, causing issues in stream processing. NewKeepAliveReader addresses this by regularly reading a byte from the stream when there are no Read calls and buffering it for the next Read call.
Example ¶
package main import ( "bytes" "io" "time" "go.llib.dev/frameless/pkg/iokit" ) func main() { r := bytes.NewReader([]byte("reader")) kar := iokit.NewKeepAliveReader(r, 20*time.Second) defer kar.Close() var _ io.ReadCloser = kar _, _ = kar.Read(make([]byte, 10)) }
Output:
func NewKeepAliveReader ¶ added in v0.218.2
func NewKeepAliveReader(r io.Reader, d time.Duration) *KeepAliveReader
func (*KeepAliveReader) Close ¶ added in v0.218.2
func (r *KeepAliveReader) Close() error
func (*KeepAliveReader) Init ¶ added in v0.218.2
func (r *KeepAliveReader) Init()
type RuneReader ¶ added in v0.258.0
type RuneUnreader ¶ added in v0.258.0
type RuneUnreader interface {
UnreadRune() error
}
type RuneWriter ¶ added in v0.258.0
type StubReader ¶ added in v0.202.0
type StubReader struct { Data []byte ReadErr error CloseErr error // contains filtered or unexported fields }
func (*StubReader) Close ¶ added in v0.202.0
func (r *StubReader) Close() error
func (*StubReader) IsClosed ¶ added in v0.202.0
func (r *StubReader) IsClosed() bool
func (*StubReader) LastReadAt ¶ added in v0.218.2
func (r *StubReader) LastReadAt() time.Time
type SyncReadWriter ¶
type SyncReadWriter struct { // ReadWriter is the protected io.ReadWriter ReadWriter io.ReadWriter // Locker is an optional sync.Locker value if you need to share locking between different multiple SyncReader. // // Default: sync.Mutex Locker sync.Locker }