io

package
v0.0.0-...-27647ab Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 17, 2023 License: BSD-3-Clause Imports: 7 Imported by: 9

Documentation

Overview

Copyright 2022 The Go Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Discard

func Discard(n int, err error)

func DiscardLen

func DiscardLen(n int, err error) error

func FprintfDiscard

func FprintfDiscard(w io.Writer, format string, a ...any)

func FprintfErr

func FprintfErr(w io.Writer, format string, a ...any) error

func InvokeToString

func InvokeToString(fn func(writer DiscardStringWriter)) string

func SafeReadData

func SafeReadData(r io.Reader, n uint64, chunkSize uint64) ([]byte, error)

ReadData reads n bytes from the input stream, but avoids allocating all n bytes if n is large. This avoids crashing the program by allocating all n bytes in cases where n is incorrect.

The error is io.EOF only if no bytes were read. If an io.EOF happens after reading some but not all the bytes, ReadData returns io.ErrUnexpectedEOF.

func SafeReadDataAt

func SafeReadDataAt(r io.ReaderAt, n uint64, off int64, chunkSize uint64) ([]byte, error)

ReadDataAt reads n bytes from the input stream at off, but avoids allocating all n bytes if n is large. This avoids crashing the program by allocating all n bytes in cases where n is incorrect.

func SafeSliceCap

func SafeSliceCap(v any, c uint64, chunkSize uint64) int

SliceCap returns the capacity to use when allocating a slice. After the slice is allocated with the capacity, it should be built using append. This will avoid allocating too much memory if the capacity is large and incorrect.

A negative result means that the value is always too big.

The element type is described by passing a pointer to a value of that type. This would ideally use generics, but this code is built with the bootstrap compiler which need not support generics. We use a pointer so that we can handle slices of interface type.

func WriteAdd

func WriteAdd(w io.Writer, p []byte, n *int) error

func WriteByte

func WriteByte(w io.Writer, b byte) (int, error)

func WriteByteDiscard

func WriteByteDiscard(w io.Writer, b byte)

func WriteByteErr

func WriteByteErr(w io.Writer, b byte) error

func WriteDiscard

func WriteDiscard(w io.Writer, p []byte)

func WriteErr

func WriteErr(w io.Writer, p []byte) error

func WriteString

func WriteString(w io.Writer, s string) (int, error)

func WriteStringAdd

func WriteStringAdd(w io.StringWriter, s string, n *int) error

func WriteStringDiscard

func WriteStringDiscard(w io.Writer, s string)

func WriteStringErr

func WriteStringErr(w io.Writer, s string) error

Types

type DiscardStringWriter

type DiscardStringWriter interface {
	WriteString(string)
}

func NewDiscardStringWriter

func NewDiscardStringWriter(w io.StringWriter) DiscardStringWriter

type DiscardingWriter

type DiscardingWriter struct {
	io.Writer
}

func Dw

func (DiscardingWriter) Byte

func (DiscardingWriter) Bytes

func (d DiscardingWriter) Bytes(p []byte) DiscardingWriter

func (DiscardingWriter) Fprintf

func (d DiscardingWriter) Fprintf(format string, a ...any) DiscardingWriter

func (DiscardingWriter) String

type IndentWriter

type IndentWriter struct {
	// contains filtered or unexported fields
}

func NewIndentWriter

func NewIndentWriter(w DiscardStringWriter, indent string) *IndentWriter

func (*IndentWriter) Dedent

func (w *IndentWriter) Dedent()

func (*IndentWriter) Indent

func (w *IndentWriter) Indent()

func (*IndentWriter) WriteString

func (w *IndentWriter) WriteString(s string)

type OffsetReaderAt

type OffsetReaderAt struct {
	Off int64
	R   io.ReaderAt
}

func (OffsetReaderAt) ReadAt

func (r OffsetReaderAt) ReadAt(p []byte, off int64) (n int, err error)

type PooledBufioWriter

type PooledBufioWriter struct {
	// contains filtered or unexported fields
}

func NewPooledBufioWriter

func NewPooledBufioWriter(
	u io.Writer,
	p pools.Pool[*bufio.Writer],
	b *bufio.Writer,
) *PooledBufioWriter

func (*PooledBufioWriter) Flush

func (pw *PooledBufioWriter) Flush() error

func (*PooledBufioWriter) Get

func (pw *PooledBufioWriter) Get() *bufio.Writer

func (*PooledBufioWriter) Pooled

func (pw *PooledBufioWriter) Pooled() *bufio.Writer

func (*PooledBufioWriter) Write

func (pw *PooledBufioWriter) Write(p []byte) (n int, err error)

type ReaderAtReader

type ReaderAtReader struct {
	Off int64
	R   io.ReaderAt
}

func (*ReaderAtReader) Read

func (r *ReaderAtReader) Read(p []byte) (n int, err error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL