Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var Debug bool
Functions ¶
func Explode ¶
Explode the archive by looking at the file MagicBytes and then try that archive reader so as to extract layers of archives all at once.
Some layers are represented in a single extraction, while others, like tgz are actually two layers, a gzip on the first and a tar on the second. If a file is unable to be extracted it will be saved as the original name and bytes in the corresponding child folder.
One MUST provide an io.Reader and SHOULD provide the Size of provided reader for extraction. If the size is not known, use -1.
The Explode can work on io.Reader alone, such as an incoming stream from a web upload. In such cases the size can be set to -1 if it is unknown.
The filePath is the directory in which the extracted content should be placed.
Important: If one is reading from a slow media source (like a disk), a bufio.Buffer will help performance. Something like this:
fh, err := os.Open("myArchive") stat, _ := fh.Stat() err = exploder.Explode(data, bufio.NewReader(file), stat.Size(), 10)
Example ¶
fh, err := os.Open("testdata.zip") // Open a file if err != nil { log.Fatal(err) } stat, err := fh.Stat() // Stat the file to get the size if err != nil { log.Fatal(err) } outputPath := "output/" err = exploder.Explode(outputPath, fh, stat.Size(), -1)
Output:
func ExplodeFunc ¶
func ExplodeFunc(HandleFile func(filePath string, r *FileReader) error, in io.Reader, size int64, recursion int) (err error)
Similar to the Explode, but provides a custom call back function for each file.
Types ¶
type FileReader ¶
type FileReader struct {
// contains filtered or unexported fields
}
FileReader provides the ability to read the underlying bytes from a file in an archive.
func (*FileReader) Read ¶
func (r *FileReader) Read(p []byte) (n int, err error)
Read implement the io.Reader interface
func (*FileReader) Size ¶
func (r *FileReader) Size() int64
Return the size if known, other wise determine the size by reading off the buffer and then returning the size.