partialzip

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2018 License: MIT Imports: 14 Imported by: 3

README

partialzip

GoDoc License

Partial Implementation of PartialZip in Go


Install

go get github.com/blacktop/partialzip

Examples

import (
    "fmt"

    "github.com/blacktop/partialzip"
)

func main() {
    pzip, err := partialzip.New("https://apple.com/ipsw/download/link")
    if err != nil {
        log.Fatal(err)
    }
    fmt.Println(pzip.List())

    n, err := pzip.Get("kernelcache.release.iphone11")
    if err != nil {
        log.Fatal(err)
    }
    fmt.Printf("extracting %s, wrote %d bytes\n", "kernelcache.release.iphone11", n)

    n, err = pzip.Get("BuildManifest.plist")
    if err != nil {
        log.Fatal(err)
    }
    fmt.Printf("extracting %s, wrote %d bytes\n", "BuildManifest.plist", n)
}
extracting "kernelcache.release.iphone11", wrote 17842148 bytes
extracting "BuildManifest.plist", wrote 206068 bytes

Credits

License

MIT Copyright (c) 2018 blacktop

Documentation

Overview

Package partialzip is a Go package to pull single files our of large remote zip archives.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrFormat    = errors.New("zip: not a valid zip file")
	ErrAlgorithm = errors.New("zip: unsupported compression algorithm")
	ErrChecksum  = errors.New("zip: checksum error")
)

Functions

This section is empty.

Types

type File

type File struct {
	FileHeader

	DataOffset int64 // Offsetr to data start
	// contains filtered or unexported fields
}

type FileHeader

type FileHeader struct {
	// Name is the name of the file.
	//
	// It must be a relative path, not start with a drive letter (such as "C:"),
	// and must use forward slashes instead of back slashes. A trailing slash
	// indicates that this file is a directory and should have no data.
	//
	// When reading zip files, the Name field is populated from
	// the zip file directly and is not validated for correctness.
	// It is the caller's responsibility to sanitize it as
	// appropriate, including canonicalizing slash directions,
	// validating that paths are relative, and preventing path
	// traversal through filenames ("../../../").
	Name string

	// Comment is any arbitrary user-defined string shorter than 64KiB.
	Comment string

	// NonUTF8 indicates that Name and Comment are not encoded in UTF-8.
	//
	// By specification, the only other encoding permitted should be CP-437,
	// but historically many ZIP readers interpret Name and Comment as whatever
	// the system's local character encoding happens to be.
	//
	// This flag should only be set if the user intends to encode a non-portable
	// ZIP file for a specific localized region. Otherwise, the Writer
	// automatically sets the ZIP format's UTF-8 flag for valid UTF-8 strings.
	NonUTF8 bool

	CreatorVersion uint16
	ReaderVersion  uint16
	Flags          uint16

	// Method is the compression method. If zero, Store is used.
	Method uint16

	// Modified is the modified time of the file.
	//
	// When reading, an extended timestamp is preferred over the legacy MS-DOS
	// date field, and the offset between the times is used as the timezone.
	// If only the MS-DOS date is present, the timezone is assumed to be UTC.
	//
	// When writing, an extended timestamp (which is timezone-agnostic) is
	// always emitted. The legacy MS-DOS date field is encoded according to the
	// location of the Modified time.
	Modified     time.Time
	ModifiedTime uint16 // Deprecated: Legacy MS-DOS date; use Modified instead.
	ModifiedDate uint16 // Deprecated: Legacy MS-DOS time; use Modified instead.

	CRC32              uint32
	CompressedSize     uint32 // Deprecated: Use CompressedSize64 instead.
	UncompressedSize   uint32 // Deprecated: Use UncompressedSize64 instead.
	CompressedSize64   uint64
	UncompressedSize64 uint64
	Extra              []byte
	ExternalAttrs      uint32 // Meaning depends on CreatorVersion
}

type PartialZip

type PartialZip struct {
	URL   string
	Size  int64
	Files []*File
}

PartialZip defines a custom partialzip object

func New

func New(url string) (*PartialZip, error)

New returns a newly created partialzip object.

func (*PartialZip) Get

func (p *PartialZip) Get(path string) (int, error)

Get downloads a file from the remote zip. It returns the number of bytes written and an error, if any.

func (*PartialZip) List

func (p *PartialZip) List() []string

List lists the files in the remote zip. It returns a string array of file paths.

Directories

Path Synopsis
cli

Jump to

Keyboard shortcuts

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