vendor: github.com/philhofer/fwd v1.2.0

full diff: https://github.com/philhofer/fwd/compare/v1.1.2...v1.2.0

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2025-08-08 19:44:47 +02:00
parent 414e5f3b3d
commit 27b609b401
6 changed files with 81 additions and 15 deletions

2
go.mod
View File

@@ -195,7 +195,7 @@ require (
github.com/package-url/packageurl-go v0.1.1 // indirect
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
github.com/petermattis/goid v0.0.0-20240813172612-4fcff4a6cae7 // indirect
github.com/philhofer/fwd v1.1.2 // indirect
github.com/philhofer/fwd v1.2.0 // indirect
github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.6.1 // indirect

3
go.sum
View File

@@ -490,8 +490,9 @@ github.com/petermattis/goid v0.0.0-20240813172612-4fcff4a6cae7 h1:Dx7Ovyv/SFnMFw
github.com/petermattis/goid v0.0.0-20240813172612-4fcff4a6cae7/go.mod h1:pxMtw7cyUw6B2bRH0ZBANSPg+AoSud1I1iyJHI69jH4=
github.com/phayes/permbits v0.0.0-20190612203442-39d7c581d2ee h1:P6U24L02WMfj9ymZTxl7CxS73JC99x3ukk+DBkgQGQs=
github.com/phayes/permbits v0.0.0-20190612203442-39d7c581d2ee/go.mod h1:3uODdxMgOaPYeWU7RzZLxVtJHZ/x1f/iHkBZuKJDzuY=
github.com/philhofer/fwd v1.1.2 h1:bnDivRJ1EWPjUIRXV5KfORO897HTbpFAQddBdE8t7Gw=
github.com/philhofer/fwd v1.1.2/go.mod h1:qkPdfjR2SIEbspLqpe1tO4n5yICnr2DY7mqEx2tUTP0=
github.com/philhofer/fwd v1.2.0 h1:e6DnBTl7vGY+Gz322/ASL4Gyp1FspeMvx1RNDoToZuM=
github.com/philhofer/fwd v1.2.0/go.mod h1:RqIHx9QI14HlwKwm98g9Re5prTQ6LdeRQn+gXJFxsJM=
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c h1:+mdjkGKdHQG3305AYmdv1U2eRNDiU2ErMBj1gwrq8eQ=
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c/go.mod h1:7rwL4CYBLnjLxUqIJNnCWiEdr3bn6IUYi15bNlnbCCU=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=

View File

@@ -45,6 +45,15 @@ the write position by the length of the returned slice. This allows users
to write directly to the end of the buffer.
## Portability
Because it uses the unsafe package, there are theoretically
no promises about forward or backward portability.
To stay compatible with tinygo 0.32, unsafestr() has been updated
to use unsafe.Slice() as suggested by
https://tinygo.org/docs/guides/compatibility, which also required
bumping go.mod to require at least go 1.20.
## <a name="pkg-index">Index</a>

View File

@@ -82,9 +82,10 @@ type Reader struct {
r io.Reader // underlying reader
// data[n:len(data)] is buffered data; data[len(data):cap(data)] is free buffer space
data []byte // data
n int // read offset
state error // last read error
data []byte // data
n int // read offset
inputOffset int64 // offset in the input stream
state error // last read error
// if the reader past to NewReader was
// also an io.Seeker, this is non-nil
@@ -97,6 +98,7 @@ func (r *Reader) Reset(rd io.Reader) {
r.r = rd
r.data = r.data[0:0]
r.n = 0
r.inputOffset = 0
r.state = nil
if s, ok := rd.(io.Seeker); ok {
r.rs = s
@@ -158,6 +160,9 @@ func (r *Reader) Buffered() int { return len(r.data) - r.n }
// BufferSize returns the total size of the buffer
func (r *Reader) BufferSize() int { return cap(r.data) }
// InputOffset returns the input stream byte offset of the current reader position
func (r *Reader) InputOffset() int64 { return r.inputOffset }
// Peek returns the next 'n' buffered bytes,
// reading from the underlying reader if necessary.
// It will only return a slice shorter than 'n' bytes
@@ -191,16 +196,50 @@ func (r *Reader) Peek(n int) ([]byte, error) {
return r.data[r.n : r.n+n], nil
}
func (r *Reader) PeekByte() (b byte, err error) {
if len(r.data)-r.n >= 1 {
b = r.data[r.n]
} else {
b, err = r.peekByte()
}
return
}
func (r *Reader) peekByte() (byte, error) {
const n = 1
if cap(r.data) < n {
old := r.data[r.n:]
r.data = make([]byte, n+r.buffered())
r.data = r.data[:copy(r.data, old)]
r.n = 0
}
// keep filling until
// we hit an error or
// read enough bytes
for r.buffered() < n && r.state == nil {
r.more()
}
// we must have hit an error
if r.buffered() < n {
return 0, r.err()
}
return r.data[r.n], nil
}
// discard(n) discards up to 'n' buffered bytes, and
// and returns the number of bytes discarded
func (r *Reader) discard(n int) int {
inbuf := r.buffered()
if inbuf <= n {
r.n = 0
r.inputOffset += int64(inbuf)
r.data = r.data[:0]
return inbuf
}
r.n += n
r.inputOffset += int64(n)
return n
}
@@ -228,6 +267,7 @@ func (r *Reader) Skip(n int) (int, error) {
// if we can Seek() through the remaining bytes, do that
if n > skipped && r.rs != nil {
nn, err := r.rs.Seek(int64(n-skipped), 1)
r.inputOffset += nn
return int(nn) + skipped, err
}
// otherwise, keep filling the buffer
@@ -248,7 +288,18 @@ func (r *Reader) Skip(n int) (int, error) {
// If an the returned slice is less than the
// length asked for, an error will be returned,
// and the reader position will not be incremented.
func (r *Reader) Next(n int) ([]byte, error) {
func (r *Reader) Next(n int) (b []byte, err error) {
if r.state == nil && len(r.data)-r.n >= n {
b = r.data[r.n : r.n+n]
r.n += n
r.inputOffset += int64(n)
} else {
b, err = r.next(n)
}
return
}
func (r *Reader) next(n int) ([]byte, error) {
// in case the buffer is too small
if cap(r.data) < n {
old := r.data[r.n:]
@@ -267,6 +318,7 @@ func (r *Reader) Next(n int) ([]byte, error) {
}
out := r.data[r.n : r.n+n]
r.n += n
r.inputOffset += int64(n)
return out, nil
}
@@ -277,6 +329,7 @@ func (r *Reader) Read(b []byte) (int, error) {
if r.buffered() != 0 {
x := copy(b, r.data[r.n:])
r.n += x
r.inputOffset += int64(x)
return x, nil
}
var n int
@@ -293,6 +346,9 @@ func (r *Reader) Read(b []byte) (int, error) {
if n == 0 {
return 0, r.err()
}
r.inputOffset += int64(n)
return n, nil
}
@@ -312,9 +368,11 @@ func (r *Reader) ReadFull(b []byte) (int, error) {
nn = copy(b[n:], r.data[r.n:])
n += nn
r.n += nn
r.inputOffset += int64(nn)
} else if l-n > cap(r.data) {
nn, r.state = r.r.Read(b[n:])
n += nn
r.inputOffset += int64(nn)
} else {
r.more()
}
@@ -335,6 +393,8 @@ func (r *Reader) ReadByte() (byte, error) {
}
b := r.data[r.n]
r.n++
r.inputOffset++
return b, nil
}
@@ -354,6 +414,7 @@ func (r *Reader) WriteTo(w io.Writer) (int64, error) {
}
r.data = r.data[0:0]
r.n = 0
r.inputOffset += int64(ii)
}
for r.state == nil {
// here we just do
@@ -367,6 +428,7 @@ func (r *Reader) WriteTo(w io.Writer) (int64, error) {
}
r.data = r.data[0:0]
r.n = 0
r.inputOffset += int64(ii)
}
}
if r.state != io.EOF {

View File

@@ -4,16 +4,10 @@
package fwd
import (
"reflect"
"unsafe"
)
// unsafe cast string as []byte
func unsafestr(b string) []byte {
l := uintptr(len(b))
return *(*[]byte)(unsafe.Pointer(&reflect.SliceHeader{
Len: l,
Cap: l,
Data: (*reflect.StringHeader)(unsafe.Pointer(&b)).Data,
}))
return unsafe.Slice(unsafe.StringData(b), len(b))
}

4
vendor/modules.txt vendored
View File

@@ -1140,8 +1140,8 @@ github.com/pelletier/go-toml/v2/unstable
# github.com/petermattis/goid v0.0.0-20240813172612-4fcff4a6cae7
## explicit; go 1.17
github.com/petermattis/goid
# github.com/philhofer/fwd v1.1.2
## explicit; go 1.15
# github.com/philhofer/fwd v1.2.0
## explicit; go 1.20
github.com/philhofer/fwd
# github.com/pkg/errors v0.9.1
## explicit