Standard library / archive/zip
archive/zip.File.OpenRaw()
Read stored bytes without decompression or checksum verification. Example uses Store so raw bytes equal original. Expected stdout: 'Go\n'.
Formal Syntax & Structure
go syntaxgo
func (f *File) OpenRaw() (io.Reader, error)Return Value
(io.Reader, error)
Raw entry stream and error.
Working Example
Example Snippetgo
package main
import ( "archive/zip" "bytes" "fmt" "io")
func must(e error) { if e != nil { panic(e) }}func archive() []byte { var b bytes.Buffer w := zip.NewWriter(&b) f, e := w.CreateHeader(&zip.FileHeader{Name: "a.txt", Method: zip.Store}) must(e) _, e = f.Write([]byte("Go")) must(e) must(w.Close()) return b.Bytes()}func reader() *zip.Reader { b := archive() r, e := zip.NewReader(bytes.NewReader(b), int64(len(b))) must(e) return r}func main() { r, e := reader().File[0].OpenRaw() must(e) p, e := io.ReadAll(r) must(e) fmt.Println(string(p))}