Documentation ¶
Overview ¶
Package xio provides i/o utilities.
Index ¶
- func CloseIgnoringErrors(closer io.Closer)
- func CloseLoggingAnyError(closer io.Closer)
- func CloseLoggingAnyErrorTo(logger *slog.Logger, closer io.Closer)
- func ContextSleep(ctx context.Context, waitTime time.Duration) error
- func ContextWasCanceled(ctx context.Context) bool
- func ContexterWasCanceled(ctxer Contexter) bool
- func DiscardAndCloseIgnoringErrors(rc io.ReadCloser)
- func NewBOMStripper(r io.Reader) (*bufio.Reader, error)
- func RetrieveData(filePathOrURL string) ([]byte, error)
- func RetrieveDataFromURL(urlStr string) ([]byte, error)
- func RetrieveDataFromURLWithContext(ctx context.Context, urlStr string) ([]byte, error)
- func RetrieveDataWithContext(ctx context.Context, filePathOrURL string) ([]byte, error)
- type ByteBuffer
- func (b *ByteBuffer) Bytes() []byte
- func (b *ByteBuffer) Cap() int
- func (b *ByteBuffer) Insert(index int, data []byte) error
- func (b *ByteBuffer) InsertByte(index int, ch byte) error
- func (b *ByteBuffer) InsertRune(index int, r rune) error
- func (b *ByteBuffer) InsertString(index int, s string) error
- func (b *ByteBuffer) Len() int
- func (b *ByteBuffer) Reset()
- func (b *ByteBuffer) String() string
- func (b *ByteBuffer) Truncate(n int)
- func (b *ByteBuffer) Write(data []byte) (int, error)
- func (b *ByteBuffer) WriteByte(ch byte) error
- func (b *ByteBuffer) WriteRune(r rune) (int, error)
- func (b *ByteBuffer) WriteString(s string) (int, error)
- func (b *ByteBuffer) WriteTo(w io.Writer) (int64, error)
- type Contexter
- type LineWriter
- type TeeWriter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CloseIgnoringErrors ¶
CloseIgnoringErrors closes the closer and ignores any error it might produce. Should only be used for read-only streams of data where closing should never cause an error.
func CloseLoggingAnyError ¶ added in v1.116.0
CloseLoggingAnyError closes the closer and logs any error that occurs at an error level to the default logger.
func CloseLoggingAnyErrorTo ¶ added in v1.116.0
CloseLoggingAnyErrorTo closes the closer and logs any error that occurs to the provided logger.
func ContextSleep ¶ added in v1.29.0
ContextSleep sleeps for the specified time, or until the context is done. You can check the return error to see if the context deadline was exceeded by using errors.Is(err, context.DeadlineExceeded).
func ContextWasCanceled ¶ added in v1.117.0
ContextWasCanceled checks the context to see if it was canceled.
func ContexterWasCanceled ¶ added in v1.117.0
ContexterWasCanceled checks the context held by the contexter to see if it was canceled.
func DiscardAndCloseIgnoringErrors ¶ added in v1.39.0
func DiscardAndCloseIgnoringErrors(rc io.ReadCloser)
DiscardAndCloseIgnoringErrors reads any content remaining in the body and discards it, then closes the body.
func NewBOMStripper ¶ added in v1.94.0
NewBOMStripper strips a leading UTF-8 BOM marker from the input. The reader that is returned will be the same as the one passed in if it was a *bufio.Reader, otherwise, the original reader will be wrapped with a *bufio.Reader and returned.
func RetrieveData ¶ added in v1.50.0
RetrieveData loads the bytes from the given file path or URL of type file, http, or https.
func RetrieveDataFromURL ¶ added in v1.23.0
RetrieveDataFromURL loads the bytes from the given URL of type file, http, or https.
func RetrieveDataFromURLWithContext ¶ added in v1.52.0
RetrieveDataFromURLWithContext loads the bytes from the given URL of type file, http, or https.
Types ¶
type ByteBuffer ¶ added in v1.57.0
type ByteBuffer struct {
// contains filtered or unexported fields
}
ByteBuffer is a variable-sized buffer of bytes with Write and Insert methods. The zero value for ByteBuffer is an empty buffer ready to use.
func (*ByteBuffer) Bytes ¶ added in v1.57.0
func (b *ByteBuffer) Bytes() []byte
Bytes returns the underlying buffer of bytes.
func (*ByteBuffer) Cap ¶ added in v1.57.0
func (b *ByteBuffer) Cap() int
Cap returns the capacity of the buffer.
func (*ByteBuffer) Insert ¶ added in v1.57.0
func (b *ByteBuffer) Insert(index int, data []byte) error
Insert data at the given offset.
func (*ByteBuffer) InsertByte ¶ added in v1.57.0
func (b *ByteBuffer) InsertByte(index int, ch byte) error
InsertByte inserts a byte at the given offset.
func (*ByteBuffer) InsertRune ¶ added in v1.57.0
func (b *ByteBuffer) InsertRune(index int, r rune) error
InsertRune inserts the UTF-8 encoding of the rune at the given offset.
func (*ByteBuffer) InsertString ¶ added in v1.57.0
func (b *ByteBuffer) InsertString(index int, s string) error
InsertString inserts the string at the given offset.
func (*ByteBuffer) Len ¶ added in v1.57.0
func (b *ByteBuffer) Len() int
Len returns the number of bytes contained by the buffer.
func (*ByteBuffer) Reset ¶ added in v1.57.0
func (b *ByteBuffer) Reset()
Reset resets the buffer to be empty.
func (*ByteBuffer) String ¶ added in v1.57.0
func (b *ByteBuffer) String() string
String returns the underlying buffer of bytes as a string. If the ByteBuffer is a nil pointer, it returns "<nil>".
func (*ByteBuffer) Truncate ¶ added in v1.57.0
func (b *ByteBuffer) Truncate(n int)
Truncate discards all but the first n bytes from the buffer.
func (*ByteBuffer) Write ¶ added in v1.57.0
func (b *ByteBuffer) Write(data []byte) (int, error)
Write appends the contents of data to the buffer.
func (*ByteBuffer) WriteByte ¶ added in v1.57.0
func (b *ByteBuffer) WriteByte(ch byte) error
WriteByte appends the byte to the buffer.
func (*ByteBuffer) WriteRune ¶ added in v1.57.0
func (b *ByteBuffer) WriteRune(r rune) (int, error)
WriteRune appends the UTF-8 encoding of the rune to the buffer.
func (*ByteBuffer) WriteString ¶ added in v1.57.0
func (b *ByteBuffer) WriteString(s string) (int, error)
WriteString appends the string to the buffer.
type LineWriter ¶
type LineWriter struct {
// contains filtered or unexported fields
}
LineWriter buffers its input into lines before sending each line to an output function without the trailing line feed.
func NewLineWriter ¶
func NewLineWriter(out func([]byte)) *LineWriter
NewLineWriter creates a new LineWriter.
func (*LineWriter) Close ¶
func (w *LineWriter) Close() error
Close implements the io.Closer interface.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package fs provides filesystem-related utilities.
|
Package fs provides filesystem-related utilities. |
paths
Package paths provides platform-specific standard paths.
|
Package paths provides platform-specific standard paths. |
safe
Package safe provides safe, atomic saving of files.
|
Package safe provides safe, atomic saving of files. |
tar
Package tar provides simple tar extraction.
|
Package tar provides simple tar extraction. |
zip
Package zip provides simple zip extraction.
|
Package zip provides simple zip extraction. |
Package network provides network-related utilities.
|
Package network provides network-related utilities. |
natpmp
Package natpmp provides an implementation of NAT-PMP.
|
Package natpmp provides an implementation of NAT-PMP. |
xhttp
Package xhttp provides HTTP-related utilities.
|
Package xhttp provides HTTP-related utilities. |
Package term provides terminal utilities.
|
Package term provides terminal utilities. |