zipslicer

package
v7.2.1+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 31, 2019 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TarMemberCD  = "zipdir.bin"
	TarMemberZip = "contents.zip"
)

Variables

This section is empty.

Functions

func FindDirectory

func FindDirectory(r io.ReaderAt, size int64) (int64, error)

Return the offset of the zip central directory

func ZipToTar

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.

Types

type Directory

type Directory struct {
	File   []*File
	Size   int64
	DirLoc int64
	// contains filtered or unexported fields
}

func Read

func Read(r io.ReaderAt, size int64) (*Directory, error)

Read a zip from a ReaderAt

func ReadStream

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

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

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 (*Directory) AddFile

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 (*Directory) GetOriginalDirectory

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 (*Directory) Mangle

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 (*Directory) NewFile

func (d *Directory) NewFile(name string, extra, contents []byte, w io.Writer, mtime time.Time, deflate, useDesc bool) (*File, error)

func (*Directory) NextFileOffset

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 (*Directory) Truncate

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 (*Directory) WriteDirectory

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

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 (*File) Digest

func (f *File) Digest(hash crypto.Hash) ([]byte, error)

func (*File) Dump

func (f *File) Dump(w io.Writer) (int64, error)

Dump the local header and contents of this file to a writer

func (*File) GetDataDescriptor

func (f *File) GetDataDescriptor() ([]byte, error)

func (*File) GetDirectoryHeader

func (f *File) GetDirectoryHeader() ([]byte, error)

func (*File) GetLocalHeader

func (f *File) GetLocalHeader() ([]byte, error)

func (*File) GetTotalSize

func (f *File) GetTotalSize() (int64, error)

func (*File) ModTime

func (f *File) ModTime() time.Time

func (*File) Open

func (f *File) Open() (io.ReadCloser, error)

func (*File) OpenAndTeeRaw

func (f *File) OpenAndTeeRaw(sink io.Writer) (*Reader, error)

Open zip file for reading, but also write raw zip data to 'sink'.

type MangleFile

type MangleFile struct {
	File
	// contains filtered or unexported fields
}

func (*MangleFile) Delete

func (f *MangleFile) Delete()

Mark this file for deletion

type MangleFunc

type MangleFunc func(*MangleFile) error

type Mangler

type Mangler struct {
	// contains filtered or unexported fields
}

func (*Mangler) MakePatch

func (m *Mangler) MakePatch(forceZip64 bool) (*binpatch.PatchSet, error)

Create a binary patchset out of the operations performed in this mangler

func (*Mangler) NewFile

func (m *Mangler) NewFile(name string, contents []byte) error

Add a new file to a zip mangler

type Reader

type Reader struct {
	// contains filtered or unexported fields
}

func (*Reader) Close

func (r *Reader) Close() error

func (*Reader) Read

func (r *Reader) Read(d []byte) (int, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL