github.com/vc42/parquet-go@v0.0.0-20240320194221-1a9adb5f23f5/internal/debug/debug.go (about)

     1  package debug
     2  
     3  import (
     4  	"fmt"
     5  	"io"
     6  )
     7  
     8  func ReaderAt(reader io.ReaderAt, prefix string) io.ReaderAt {
     9  	return &ioReaderAt{
    10  		reader: reader,
    11  		prefix: prefix,
    12  	}
    13  }
    14  
    15  type ioReaderAt struct {
    16  	reader io.ReaderAt
    17  	prefix string
    18  }
    19  
    20  func (d *ioReaderAt) ReadAt(b []byte, off int64) (int, error) {
    21  	n, err := d.reader.ReadAt(b, off)
    22  	fmt.Printf("%s: Read(%d) @%d => %d %v \n  %q\n", d.prefix, len(b), off, n, err, b[:n])
    23  	return n, err
    24  }
    25  
    26  func Reader(reader io.Reader, prefix string) io.Reader {
    27  	return &ioReader{
    28  		reader: reader,
    29  		prefix: prefix,
    30  	}
    31  }
    32  
    33  type ioReader struct {
    34  	reader io.Reader
    35  	prefix string
    36  	offset int64
    37  }
    38  
    39  func (d *ioReader) Read(b []byte) (int, error) {
    40  	n, err := d.reader.Read(b)
    41  	fmt.Printf("%s: Read(%d) @%d => %d %v \n  %q\n", d.prefix, len(b), d.offset, n, err, b[:n])
    42  	d.offset += int64(n)
    43  	return n, err
    44  }
    45  
    46  func Writer(writer io.Writer, prefix string) io.Writer {
    47  	return &ioWriter{
    48  		writer: writer,
    49  		prefix: prefix,
    50  	}
    51  }
    52  
    53  type ioWriter struct {
    54  	writer io.Writer
    55  	prefix string
    56  	offset int64
    57  }
    58  
    59  func (d *ioWriter) Write(b []byte) (int, error) {
    60  	n, err := d.writer.Write(b)
    61  	fmt.Printf("%s: Write(%d) @%d => %d %v \n  %q\n", d.prefix, len(b), d.offset, n, err, b[:n])
    62  	d.offset += int64(n)
    63  	return n, err
    64  }