Skip to content

proposal: archive/zip: File.OpenRaw() should return io.NewSectionReader #67116

Description

@krum110487

Proposal Details

Right now as implemented in OpenRaw() it uses a NewSectionReader to return a reader so that it could have a Read, Seek and ReadAt, but for whatever reason it is returning just an io.Reader implementation meaning that with OpenRaw it is not seekable.

Is there a good reason why the function returns io.Reader and not io.ReadSeeker so we can have more access to the bytes?

It seems like a very easy modification from:

func (f *File) OpenRaw() (io.Reader, error) {
	bodyOffset, err := f.findBodyOffset()
	if err != nil {
		return nil, err
	}
	r := io.NewSectionReader(f.zipr, f.headerOffset+bodyOffset, int64(f.CompressedSize64))
	return r, nil
}

to

func (f *File) OpenRaw() (io.ReadSeeker, error) {
	bodyOffset, err := f.findBodyOffset()
	if err != nil {
		return nil, err
	}
	r := io.NewSectionReader(f.zipr, f.headerOffset+bodyOffset, int64(f.CompressedSize64))
	return r, nil
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions