MCPcopy Create free account
hub / github.com/bodgit/sevenzip / init

Method init

reader.go:384–582  ·  view source on GitHub ↗

nolint:cyclop,funlen,gocognit,gocyclo,maintidx

(r io.ReaderAt, size int64)

Source from the content-addressed store, hash-verified

382
383//nolint:cyclop,funlen,gocognit,gocyclo,maintidx
384func (z *Reader) init(r io.ReaderAt, size int64) (err error) {
385 h := crc32.NewIEEE()
386 tra := plumbing.TeeReaderAt(r, h)
387
388 var (
389 signature = []byte{'7', 'z', 0xbc, 0xaf, 0x27, 0x1c}
390 offsets []int64
391 )
392
393 offsets, err = findSignature(r, signature)
394 if err != nil {
395 return err
396 }
397
398 if len(offsets) == 0 {
399 return errFormat
400 }
401
402 var (
403 sr *io.SectionReader
404 off int64
405 start startHeader
406 )
407
408 for _, off = range offsets {
409 sr = io.NewSectionReader(tra, off, size-off) // Will only read first 32 bytes
410
411 var sh signatureHeader
412 if err = binary.Read(sr, binary.LittleEndian, &sh); err != nil {
413 return fmt.Errorf("sevenzip: error reading signature header: %w", err)
414 }
415
416 z.r = r
417
418 h.Reset()
419
420 if err = binary.Read(sr, binary.LittleEndian, &start); err != nil {
421 return fmt.Errorf("sevenzip: error reading start header: %w", err)
422 }
423
424 // CRC of the start header should match
425 if util.CRC32Equal(h.Sum(nil), sh.CRC) {
426 break
427 }
428
429 err = errChecksum
430 }
431
432 if err != nil {
433 return err
434 }
435
436 // Work out where we are in the file (32, avoiding magic numbers)
437 if z.start, err = sr.Seek(0, io.SeekCurrent); err != nil {
438 return fmt.Errorf("sevenzip: error seeking current position: %w", err)
439 }
440
441 // Seek over the streams

Callers 2

OpenReaderWithPasswordFunction · 0.80
NewReaderWithPasswordFunction · 0.80

Calls 15

folderReaderMethod · 0.95
CRC32EqualFunction · 0.92
ByteReadCloserFunction · 0.92
findSignatureFunction · 0.85
readHeaderFunction · 0.85
readStreamsInfoFunction · 0.85
readEncodedHeaderFunction · 0.85
FoldersMethod · 0.80
ChecksumMethod · 0.80
FileInfoMethod · 0.80
FileFolderAndSizeMethod · 0.80
ReadMethod · 0.45

Tested by

no test coverage detected