aboutsummaryrefslogtreecommitdiff
path: root/format/packfile/ingest/use.go
diff options
context:
space:
mode:
Diffstat (limited to 'format/packfile/ingest/use.go')
-rw-r--r--format/packfile/ingest/use.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/format/packfile/ingest/use.go b/format/packfile/ingest/use.go
new file mode 100644
index 00000000..97f8757a
--- /dev/null
+++ b/format/packfile/ingest/use.go
@@ -0,0 +1,34 @@
+package ingest
+
+import (
+ "fmt"
+ "hash/crc32"
+)
+
+// use consumes n unread bytes and updates accounting/checksum state.
+func (scanner *streamScanner) use(n int) error {
+ if n < 0 || n > scanner.n-scanner.off {
+ return fmt.Errorf("packfile/ingest: invalid consume length %d", n)
+ }
+
+ if n == 0 {
+ return nil
+ }
+
+ chunk := scanner.buf[scanner.off : scanner.off+n]
+ if scanner.hashEnabled {
+ _, err := scanner.hash.Write(chunk)
+ if err != nil {
+ return err
+ }
+ }
+
+ if scanner.inEntryCRC {
+ scanner.entryCRC = crc32.Update(scanner.entryCRC, crc32.IEEETable, chunk)
+ }
+
+ scanner.off += n
+ scanner.consumed += uint64(n)
+
+ return nil
+}