Debian Codegraph @

plumbing/format/idxfile/helpers_test.go

raw
1 package idxfile_test
2
3 import (
4 "bytes"
5 "io/fs"
6 "time"
7 )
8
9 // bytesInput wraps an in-memory idx blob with a Stat method so that
10 // the [Decoder] can probe its on-disk length and apply the size
11 // formula. The interface is unexported in [Decoder]; the type
12 // assertion succeeds on any value that exposes both
13 // [io.Reader] and `Stat() (fs.FileInfo, error)`.
14 type bytesInput struct {
15 *bytes.Reader
16 size int64
17 }
18
19 func fromBytes(b []byte) *bytesInput {
20 return &bytesInput{Reader: bytes.NewReader(b), size: int64(len(b))}
21 }
22
23 func (b *bytesInput) Stat() (fs.FileInfo, error) {
24 return bytesInputInfo(b.size), nil
25 }
26
27 type bytesInputInfo int64
28
29 func (i bytesInputInfo) Name() string { return "" }
30 func (i bytesInputInfo) Size() int64 { return int64(i) }
31 func (i bytesInputInfo) Mode() fs.FileMode { return 0 }
32 func (i bytesInputInfo) ModTime() time.Time { return time.Time{} }
33 func (i bytesInputInfo) IsDir() bool { return false }
34 func (i bytesInputInfo) Sys() any { return nil }