func identifyRdr(w writer, s *siegfried.Siegfried, r io.Reader, sz int64, path, mime, mod string) { lg.set(path) c, err := s.Identify(r, path, mime) lg.err(err) if c == nil { w.writeFile(path, sz, mod, nil, err, nil) lg.reset() return } var b *siegreader.Buffer var cs []byte if checksum != nil { b = s.Buffer() var i int64 l := checksum.BlockSize() for ; ; i += int64(l) { buf, _ := b.Slice(i, l) if buf == nil { break } checksum.Write(buf) } cs = checksum.Sum(nil) checksum.Reset() } a := w.writeFile(path, sz, mod, cs, err, idChan(c)) lg.reset() if !*archive || a == config.None { return } var d decompressor if b == nil { b = s.Buffer() } switch a { case config.Zip: d, err = newZip(siegreader.ReaderFrom(b), path, sz) case config.Gzip: d, err = newGzip(b, path) case config.Tar: d, err = newTar(siegreader.ReaderFrom(b), path) case config.ARC: d, err = newARC(siegreader.ReaderFrom(b), path) case config.WARC: d, err = newWARC(siegreader.ReaderFrom(b), path) } if err != nil { writeError(w, path, sz, mod, fmt.Errorf("failed to decompress, got: %v", err)) return } for err = d.next(); err == nil; err = d.next() { if *droido { for _, v := range d.dirs() { w.writeFile(v, -1, "", nil, nil, nil) } } identifyRdr(w, s, d.reader(), d.size(), d.path(), d.mime(), d.mod()) } }
func identifyRdr(w writer, s *siegfried.Siegfried, r io.Reader, path string, sz int64, mod string) { c, err := s.Identify(path, r) if c == nil { w.writeFile(path, sz, mod, nil, fmt.Errorf("failed to identify %s, got: %v", path, err), nil) return } var b siegreader.Buffer var cs []byte if checksum != nil { b = s.Buffer() checksum.Write(siegreader.Bytes(b)) // ignore error returned here cs = checksum.Sum(nil) checksum.Reset() } a := w.writeFile(path, sz, mod, cs, err, idChan(c)) if !*archive || a == config.None { return } var d decompressor if b == nil { b = s.Buffer() } switch a { case config.Zip: d, err = newZip(siegreader.ReaderFrom(b), path, sz) case config.Gzip: d, err = newGzip(b, path) case config.Tar: d, err = newTar(siegreader.ReaderFrom(b), path) } if err != nil { w.writeFile(path, sz, mod, nil, fmt.Errorf("failed to decompress %s, got: %v", path, err), nil) return } for err = d.next(); err == nil; err = d.next() { if *droido { for _, v := range d.dirs() { w.writeFile(v, -1, "", nil, nil, nil) } } identifyRdr(w, s, d.reader(), d.path(), d.size(), d.mod()) } }