github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/cmd/internal/bio/buf.go (about) 1 // Copyright 2015 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // Package bio implements common I/O abstractions used within the Go toolchain. 6 package bio 7 8 import ( 9 "github.com/shogo82148/std/bufio" 10 "github.com/shogo82148/std/os" 11 ) 12 13 // Reader implements a seekable buffered io.Reader. 14 type Reader struct { 15 f *os.File 16 *bufio.Reader 17 } 18 19 // Writer implements a seekable buffered io.Writer. 20 type Writer struct { 21 f *os.File 22 *bufio.Writer 23 } 24 25 // Create creates the file named name and returns a Writer 26 // for that file. 27 func Create(name string) (*Writer, error) 28 29 // Open returns a Reader for the file named name. 30 func Open(name string) (*Reader, error) 31 32 // NewReader returns a Reader from an open file. 33 func NewReader(f *os.File) *Reader 34 35 func (r *Reader) MustSeek(offset int64, whence int) int64 36 37 func (w *Writer) MustSeek(offset int64, whence int) int64 38 39 func (r *Reader) Offset() int64 40 41 func (w *Writer) Offset() int64 42 43 func (r *Reader) Close() error 44 45 func (w *Writer) Close() error 46 47 func (r *Reader) File() *os.File 48 49 func (w *Writer) File() *os.File 50 51 // Slice reads the next length bytes of r into a slice. 52 // 53 // This slice may be backed by mmap'ed memory. Currently, this memory 54 // will never be unmapped. The second result reports whether the 55 // backing memory is read-only. 56 func (r *Reader) Slice(length uint64) ([]byte, bool, error) 57 58 // SliceRO returns a slice containing the next length bytes of r 59 // backed by a read-only mmap'd data. If the mmap cannot be 60 // established (limit exceeded, region too small, etc) a nil slice 61 // will be returned. If mmap succeeds, it will never be unmapped. 62 func (r *Reader) SliceRO(length uint64) []byte