Documentation
¶
Overview ¶
Package zip process a compressed file / body.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrNilReader = errors.New("reader is nil") ErrNilWriter = errors.New("writer is nil") ErrToReadReader = errors.New("fails to read the reader") ErrToCreateZipReader = errors.New("fails to create a zip.Reader") ErrInvalidIndex = errors.New("file index reference is invalid") ErrToReadFile = errors.New("fails to read file in the zip.Reader") ErrToWriteFile = errors.New("fails to write file") ErrToOpenFile = errors.New("fails to open file in the zip.Reader") )
Errors supported by the zip.Reader operations.
Functions ¶
This section is empty.
Types ¶
type Reader ¶
type Reader interface {
// NumFile returns the number of files in the compressed file / body.
NumFile() int
// Read the content of a file and return the body.
Read(index int) ([]byte, error)
// InfoFile returns the information of a file.
InfoFile(index int) (fs.FileInfo, error)
// Write the content in the io.Writer parameter.
Write(w io.Writer, index int) error
}
Reader is the interface that wraps the basic methods to process compressed file(s).
func NewReader ¶
func NewReader(input io.ReadCloser) (Reader, error)
NewReader returns a Reader interface for the zip. It receives a io.ReadCloser interface from http request or file.
Example ¶
package main
import (
"errors"
"fmt"
"os"
"github.com/gofast-pkg/zip"
"github.com/gofast-pkg/zip/testdata"
)
func main() {
file, err := os.Open(testdata.TestZipFile)
if err != nil {
panic(err)
}
defer func() {
if err = errors.Join(err, file.Close()); err != nil {
panic(err)
}
}()
r, err := zip.NewReader(file)
if err != nil {
panic(err)
}
fmt.Println(r.NumFile())
// Iterate through the files in the archive,
for i := 0; i < r.NumFile(); i++ {
var content []byte
if content, err = r.Read(i); err != nil {
panic(err)
}
fmt.Println(string(content[:5]))
fmt.Println(string(content[len(content)-5:]))
}
}
Output: 1 annee ;eur;
Click to show internal directories.
Click to hide internal directories.