package zio
import "zgo.at/zstd/zio"
Package zio implements some I/O utility functions.
Index ¶
- func ChangedFrom(file, base string) bool
- func Count(ctx context.Context, fp io.ReadSeeker, find []byte) (int, error)
- func DumpReader(b io.ReadCloser) (r1, r2 io.ReadCloser, err error)
- func Exists(path string) bool
- func HashReader(r io.Reader, h hash.Hash) *hashReader
- func HashWriter(w io.Writer, h hash.Hash) *hashWriter
- func LimitReader(r io.Reader, n int64) io.ReadCloser
- func NopCloser(r io.Writer) io.WriteCloser
- func PeekReader(r io.Reader, peeked []byte) io.ReadCloser
- func TeeReader(r io.Reader, w ...io.Writer) io.Reader
- type LimitedReader
- type NopWriter
Functions ¶
func ChangedFrom ¶
Newer reports if the file's mtime is more recent than base.
func Count ¶
Count the number of occurrences of find in the stream.
It will try to seek back to the original position after counting, so that something like this will just work:
fp, _ := os.Open("..") lines, _ := zio.Count(context.Background(), fp, []byte{'\n'}) scan := bufio.NewScanner(fp) var i int for scan.Scan() { fmt.Printf("line %d / %d\n", i+1, lines) i++ }
func DumpReader ¶
func DumpReader(b io.ReadCloser) (r1, r2 io.ReadCloser, err error)
DumpReader reads all of b to memory and then returns two equivalent ReadClosers which will yield the same bytes.
This is useful if you want to read data from an io.Reader more than once.
It returns an error if the initial reading of all bytes fails. It does not attempt to make the returned ReadClosers have identical error-matching behavior.
This is based on httputil.DumpRequest, see zio.DumpBody() for an example usage.
Copyright 2009 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: https://golang.org/LICENSE
func Exists ¶
Exists reports if a path exists.
func HashReader ¶
HashReader writes to the hash for all data it reads.
func HashWriter ¶
HashWriter writes to both the writer and hash.
func LimitReader ¶
func LimitReader(r io.Reader, n int64) io.ReadCloser
LimitReader returns a Reader that reads from r but stops with EOF after n bytes. The underlying implementation is a *LimitedReader.
This is identical to io.LimitReader, except that it calls Close on the reader if it has a Close method.
func NopCloser ¶
func NopCloser(r io.Writer) io.WriteCloser
NopCloser returns a WriteCloser with a no-op Close method.
func PeekReader ¶
func PeekReader(r io.Reader, peeked []byte) io.ReadCloser
PeekReader returns a reader that first returns data from peeked, before reading from the reader r.
This is useful in cases where you want to "peek" a bit data from a reader that doesn't support seeking to determine if the compression or file format.
func TeeReader ¶
TeeReader returns a [Reader] that writes to w what it reads from r.
All reads from r performed through it are matched with corresponding writes to w. There is no internal buffering - the write must complete before the read completes. Any error encountered while writing is reported as a read error.
This is simular to io.TeeReader, except that it supports multiple writers.
Types ¶
type LimitedReader ¶
A LimitedReader reads from R but limits the amount of data returned to just N bytes. Each call to Read updates N to reflect the new amount remaining.
Read returns EOF when N <= 0 or when the underlying R returns EOF.
This is identical to io.LimiterReader, except that it calls Close on the reader if it has a Close method.
func (*LimitedReader) Close ¶
func (l *LimitedReader) Close() error
Close the underlying reader if it implements a Close method.
func (*LimitedReader) Read ¶
func (l *LimitedReader) Read(p []byte) (n int, err error)
type NopWriter ¶
type NopWriter struct{}
NopWriter is an io.Writer that does nothing.
func (*NopWriter) Write ¶
Write is a stub.
Source Files ¶
zio.go
- Version
- v0.0.0-20241125224656-49fafbb06ca9 (latest)
- Published
- Nov 25, 2024
- Platform
- linux/amd64
- Imports
- 7 packages
- Last checked
- 3 days ago –
Tools for package owners.