aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--format/pack/ingest/stream.go112
-rw-r--r--format/pack/ingest/thin_fix.go2
-rw-r--r--internal/compress/zlib/reader_reset.go2
-rw-r--r--internal/compress/zlib/reader_test.go2
-rw-r--r--internal/compress/zlib/writer_test.go12
5 files changed, 72 insertions, 58 deletions
diff --git a/format/pack/ingest/stream.go b/format/pack/ingest/stream.go
index 4c6b59ab..0a496167 100644
--- a/format/pack/ingest/stream.go
+++ b/format/pack/ingest/stream.go
@@ -50,6 +50,62 @@ func newStreamScanner(src io.Reader, dstFile *os.File, hash hash.Hash, hashSize
}
}
+// Read implements io.Reader.
+func (scanner *streamScanner) Read(dst []byte) (int, error) {
+ if len(dst) == 0 {
+ return 0, nil
+ }
+
+ if scanner.n-scanner.off == 0 {
+ err := scanner.fill(1)
+ if err != nil {
+ if errors.Is(err, io.EOF) {
+ return 0, io.EOF
+ }
+
+ return 0, err
+ }
+ }
+
+ unread := scanner.n - scanner.off
+ if unread == 0 {
+ return 0, io.EOF
+ }
+
+ n := len(dst)
+ if n > unread {
+ n = unread
+ }
+
+ copy(dst, scanner.buf[scanner.off:scanner.off+n])
+
+ err := scanner.use(n)
+ if err != nil {
+ return 0, err
+ }
+
+ return n, nil
+}
+
+// ReadByte implements io.ByteReader without allocation.
+func (scanner *streamScanner) ReadByte() (byte, error) {
+ if scanner.n-scanner.off == 0 {
+ err := scanner.fill(1)
+ if err != nil {
+ return 0, err
+ }
+ }
+
+ b := scanner.buf[scanner.off]
+
+ err := scanner.use(1)
+ if err != nil {
+ return 0, err
+ }
+
+ return b, nil
+}
+
// fill ensures at least min unread bytes are available in receiver's buffer.
func (scanner *streamScanner) fill(min int) error {
if min <= 0 {
@@ -115,62 +171,6 @@ func (scanner *streamScanner) use(n int) error {
return nil
}
-// Read implements io.Reader.
-func (scanner *streamScanner) Read(dst []byte) (int, error) {
- if len(dst) == 0 {
- return 0, nil
- }
-
- if scanner.n-scanner.off == 0 {
- err := scanner.fill(1)
- if err != nil {
- if errors.Is(err, io.EOF) {
- return 0, io.EOF
- }
-
- return 0, err
- }
- }
-
- unread := scanner.n - scanner.off
- if unread == 0 {
- return 0, io.EOF
- }
-
- n := len(dst)
- if n > unread {
- n = unread
- }
-
- copy(dst, scanner.buf[scanner.off:scanner.off+n])
-
- err := scanner.use(n)
- if err != nil {
- return 0, err
- }
-
- return n, nil
-}
-
-// ReadByte implements io.ByteReader without allocation.
-func (scanner *streamScanner) ReadByte() (byte, error) {
- if scanner.n-scanner.off == 0 {
- err := scanner.fill(1)
- if err != nil {
- return 0, err
- }
- }
-
- b := scanner.buf[scanner.off]
-
- err := scanner.use(1)
- if err != nil {
- return 0, err
- }
-
- return b, nil
-}
-
// readFull reads exactly len(dst) bytes through receiver.
func (scanner *streamScanner) readFull(dst []byte) error {
_, err := io.ReadFull(scanner, dst)
diff --git a/format/pack/ingest/thin_fix.go b/format/pack/ingest/thin_fix.go
index 5883ac23..767816ed 100644
--- a/format/pack/ingest/thin_fix.go
+++ b/format/pack/ingest/thin_fix.go
@@ -275,7 +275,7 @@ func encodePackEntryHeader(ty objecttype.Type, size int64) []byte {
panic(err)
}
- c := byte((uint8(ty) << 4) | byte(s&0x0f))
+ c := (uint8(ty) << 4) | byte(s&0x0f)
s >>= 4
for s != 0 {
diff --git a/internal/compress/zlib/reader_reset.go b/internal/compress/zlib/reader_reset.go
index fbcaccac..fe675c73 100644
--- a/internal/compress/zlib/reader_reset.go
+++ b/internal/compress/zlib/reader_reset.go
@@ -57,7 +57,7 @@ func (z *Reader) reset(r io.Reader, dict []byte) error {
}
haveDict := z.scratch[1]&0x20 != 0
- if haveDict {
+ if haveDict { //nolint:nestif
readN, z.err = io.ReadFull(z.r, z.scratch[0:4])
readNUint64, err := intconv.IntToUint64(readN)
diff --git a/internal/compress/zlib/reader_test.go b/internal/compress/zlib/reader_test.go
index 6fda1f27..13f32dbc 100644
--- a/internal/compress/zlib/reader_test.go
+++ b/internal/compress/zlib/reader_test.go
@@ -151,6 +151,8 @@ var zlibTests = []zlibTest{
}
func TestDecompressor(t *testing.T) {
+ t.Parallel()
+
b := new(bytes.Buffer)
for _, tt := range zlibTests {
in := bytes.NewReader(tt.compressed)
diff --git a/internal/compress/zlib/writer_test.go b/internal/compress/zlib/writer_test.go
index b2bbd6be..2a8318a6 100644
--- a/internal/compress/zlib/writer_test.go
+++ b/internal/compress/zlib/writer_test.go
@@ -25,6 +25,8 @@ var data = []string{
// Tests that compressing and then decompressing the given file at the given compression level and dictionary
// yields equivalent bytes to the original file.
func testFileLevelDict(t *testing.T, fn string, level int, d string) {
+ t.Helper()
+
// Read the file, as golden output.
golden, err := os.Open(fn)
if err != nil {
@@ -51,6 +53,8 @@ func testFileLevelDict(t *testing.T, fn string, level int, d string) {
}
func testLevelDict(t *testing.T, fn string, b0 []byte, level int, d string) {
+ t.Helper()
+
// Make dictionary, if given.
var dict []byte
if d != "" {
@@ -135,6 +139,8 @@ func testLevelDict(t *testing.T, fn string, b0 []byte, level int, d string) {
}
func TestWriter(t *testing.T) {
+ t.Parallel()
+
for i, s := range data {
b := []byte(s)
tag := fmt.Sprintf("#%d", i)
@@ -149,6 +155,8 @@ func TestWriter(t *testing.T) {
}
func TestWriterBig(t *testing.T) {
+ t.Parallel()
+
for i, fn := range filenames {
testFileLevelDict(t, fn, DefaultCompression, "")
testFileLevelDict(t, fn, NoCompression, "")
@@ -169,6 +177,8 @@ func TestWriterBig(t *testing.T) {
}
func TestWriterDict(t *testing.T) {
+ t.Parallel()
+
const dictionary = "0123456789."
for i, fn := range filenames {
testFileLevelDict(t, fn, DefaultCompression, dictionary)
@@ -190,6 +200,8 @@ func TestWriterDict(t *testing.T) {
}
func TestWriterDictIsUsed(t *testing.T) {
+ t.Parallel()
+
var (
input = []byte("Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.")
buf bytes.Buffer