const ( TarMemberCD = "zipdir.bin" TarMemberZip = "contents.zip" )
func FindDirectory(r io.ReaderAt, size int64) (int64, error)
Return the offset of the zip central directory
func ZipToTar(r *os.File, w io.Writer) error
Make a tar archive with two members: - the central directory of the zip file - the complete zip file This lets us process the zip in one pass, which normally isn't possible with the directory at the end.
type Directory struct { File []*File Size int64 DirLoc int64 // contains filtered or unexported fields }
func Read(r io.ReaderAt, size int64) (*Directory, error)
Read a zip from a ReaderAt
func ReadStream(r io.Reader, size int64, cd []byte) (*Directory, error)
Read a zip from a stream, using a separate copy of the central directory. Contents must be read in zip order or an error will be raised.
func ReadWithDirectory(r io.ReaderAt, size int64, cd []byte) (*Directory, error)
Read a zip from a ReaderAt, with a separate copy of the central directory
func ReadZipTar(r io.Reader) (*Directory, error)
Read a tar stream produced by ZipToTar and return the zip directory. Files must be read from the zip in order or an error will be raised.
func (d *Directory) AddFile(f *File) (*File, error)
Add a file to the central directory. Its contents are assumed to be already located after the last added file.
func (d *Directory) GetOriginalDirectory(trim bool) (cdEntries, endOfDir []byte, err error)
Get the original central directory and end-of-directory from a previously-read file.
If trim is true, then the end-of-directory will be updated to skip over any non-ZIP data between the last file's contents and the first central directory entry.
func (d *Directory) Mangle(callback MangleFunc) (*Mangler, error)
Walk all the files in the directory in-order, invoking a callback that can decide whether to keep or discard each one. Returns a Mangler that can be used to add more files and eventually produce a binary patch against the original zip.
func (d *Directory) NewFile(name string, extra, contents []byte, w io.Writer, mtime time.Time, deflate, useDesc bool) (*File, error)
func (d *Directory) NextFileOffset() (int64, error)
Get the offset immediately following the last file's contents. This is the same as DirLoc unless there is non-zip data in between.
func (d *Directory) Truncate(n int, body, dir io.Writer) error
Serialize a zip file with all of the files up to, but not including, the given index. The contents and central directory are written to separate writers, which may be the same writer.
func (d *Directory) WriteDirectory(wcd, weod io.Writer, forceZip64 bool) error
Serialize a zip central directory to file. The file entries will be written to wcd, and the end-of-directory markers will be written to weod.
If forceZip64 is true then a ZIP64 end-of-directory marker will always be written; otherwise it is only done if ZIP64 features are required.
type File struct { CreatorVersion uint16 ReaderVersion uint16 Flags uint16 Method uint16 ModifiedTime uint16 ModifiedDate uint16 CRC32 uint32 CompressedSize uint64 UncompressedSize uint64 Name string Extra []byte Comment []byte InternalAttrs uint16 ExternalAttrs uint32 Offset uint64 // contains filtered or unexported fields }
func (f *File) Digest(hash crypto.Hash) ([]byte, error)
func (f *File) Dump(w io.Writer) (int64, error)
Dump the local header and contents of this file to a writer
func (f *File) GetDataDescriptor() ([]byte, error)
func (f *File) GetDirectoryHeader() ([]byte, error)
func (f *File) GetLocalHeader() ([]byte, error)
func (f *File) GetTotalSize() (int64, error)
func (f *File) ModTime() time.Time
func (f *File) Open() (io.ReadCloser, error)
func (f *File) OpenAndTeeRaw(sink io.Writer) (*Reader, error)
Open zip file for reading, but also write raw zip data to 'sink'.
type MangleFile struct { File // contains filtered or unexported fields }
func (f *MangleFile) Delete()
Mark this file for deletion
type MangleFunc func(*MangleFile) error
type Mangler struct {
// contains filtered or unexported fields
}
func (m *Mangler) MakePatch(forceZip64 bool) (*binpatch.PatchSet, error)
Create a binary patchset out of the operations performed in this mangler
func (m *Mangler) NewFile(name string, contents []byte) error
Add a new file to a zip mangler
type Reader struct {
// contains filtered or unexported fields
}
func (r *Reader) Close() error
func (r *Reader) Read(d []byte) (int, error)