// Copyright 2011 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.package tiffimport ()// buffer buffers an io.Reader to satisfy io.ReaderAt.type buffer struct { r io.Reader buf []byte}const fillChunkSize = 10 << 20// 10 MB// fill reads data from b.r until the buffer contains at least end bytes.func ( *buffer) ( int) error { := len(.buf)for < { := min(-, fillChunkSize) .buf = slices.Grow(.buf, ) .buf = .buf[:+] , := io.ReadFull(.r, .buf[:+]) += .buf = .buf[:]if != nil {return } }returnnil}func ( *buffer) ( []byte, int64) (int, error) {if < 0 {// Impossible in correct usage, but check for safety.return0, fmt.Errorf("invalid ReadAt offset %v (bug)", ) } := + int64(len())if < || > math.MaxInt {return0, io.ErrUnexpectedEOF } := int() := .fill() = min(, len(.buf))returncopy(, .buf[min(int(), ):]), }// Slice returns a slice of the underlying buffer. The slice contains// n bytes starting at offset off.func ( *buffer) (, int64) ([]byte, error) {if < 0 || < 0 {// Impossible in correct usage, but check for safety.returnnil, fmt.Errorf("invalid negative input to Slice(%v, %v) (bug)", , ) } := + if < 0 || > math.MaxInt {// end is too large. Treat this as a read error.returnnil, io.ErrUnexpectedEOF }if := .fill(int()); != nil {returnnil, }return .buf[:], nil}// newReaderAt converts an io.Reader into an io.ReaderAt.func newReaderAt( io.Reader) io.ReaderAt {if , := .(io.ReaderAt); {return }return &buffer{r: ,buf: make([]byte, 0, 1024), }}
The pages are generated with Goldsv0.8.7. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.