Conversation
fix: fix iteration bug
|
Thanks! Go 1.22 hasn't been released yet, and I doubt everyone will upgrade right away. I'll probably hold this open for a while until the release has been out for a while. |
I mean I fix the "for" loops bug (sharing of loop variables). |
|
And go 1.22 has fix it. (No more sharing of loop variables) |
|
I can't get the excepted type ArchiverExtractor struct {
archiver.Extractor
sourceArchive io.Reader
fileHandlerFunc FileHanderFunc
pathsInArchive []string
}
func (ae *ArchiverExtractor) ExtractFile(ctx context.Context, filePath string) (*archiver.File, error) {
files := make([]archiver.File, 0)
ff := FileFilter(&files, filePath)
if ae.fileHandlerFunc != nil {
ff = ae.fileHandlerFunc(&files)
}
err := ae.Extract(ctx, ae.sourceArchive, ae.pathsInArchive, ff)
if len(files) == 0 {
return nil, fmt.Errorf("file not found")
}
return &files[0], err
}
// ...
func main() {
// ...
frc, err := f.Open()
if err != nil {
panic(err)
}
defer frc.Close()
fileBytes, _ := io.ReadAll(frc) // empty
} |
|
Oh, my bad -- I understand now. Thank you. |
7z: Fix iteration bug that was already fixed in go 1.22.
The bug is same as https://github.com/mholt/archiver/blob/master/zip.go#L199