github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/internal/coverage/slicewriter/slicewriter.go (about) 1 // Copyright 2022 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 slicewriter 6 7 // WriteSeeker is a helper object that implements the io.WriteSeeker 8 // interface. Clients can create a WriteSeeker, make a series of Write 9 // calls to add data to it (and possibly Seek calls to update 10 // previously written portions), then finally invoke BytesWritten() to 11 // get a pointer to the constructed byte slice. 12 type WriteSeeker struct { 13 payload []byte 14 off int64 15 } 16 17 func (sws *WriteSeeker) Write(p []byte) (n int, err error) 18 19 // Seek repositions the read/write position of the WriteSeeker within 20 // its internally maintained slice. Note that it is not possible to 21 // expand the size of the slice using SEEK_SET; trying to seek outside 22 // the slice will result in an error. 23 func (sws *WriteSeeker) Seek(offset int64, whence int) (int64, error) 24 25 // BytesWritten returns the underlying byte slice for the WriteSeeker, 26 // containing the data written to it via Write/Seek calls. 27 func (sws *WriteSeeker) BytesWritten() []byte 28 29 func (sws *WriteSeeker) Read(p []byte) (n int, err error)