// Unzip the zip files from input channel and pass the result // to the output channel. func Unzip(c *slurp.C) slurp.Stage { return func(in <-chan slurp.File, out chan<- slurp.File) { var wg sync.WaitGroup for file := range in { wg.Add(1) go func(file slurp.File) { defer wg.Done() raw, err := ioutil.ReadAll(file) file.Close() r, err := zip.NewReader(bytes.NewReader(raw), int64(len(raw))) if err != nil { c.Error(err) return } counter := c.Counter("unzipping", len(r.File)) // Iterate through the files in the archive, for i, f := range r.File { counter.Set(i+1, f.Name) content, err := f.Open() if err != nil { } fs := slurp.File{Reader: content, Dir: "", Path: f.Name, FileInfo: slurp.FileInfoFrom(f.FileInfo())} out <- fs } }(file) } wg.Wait() } }