作者:duluma
项目:webdrive
// Extracts the entire contents of webdriver.xpi
func (s *Firefox) extractExtensionContents() (err error) {
log.Println("Installing the extension at: ", s.Extension.TargetPath)
var zipFile *zip.ReadCloser
total := 0
if _, err = os.Stat(s.Extension.Path); err == nil {
if zipFile, err = zip.OpenReader(s.Extension.Path); err == nil {
defer zipFile.Close()
for _, f := range zipFile.File {
if err = s.writeExtensionFile(f); err != nil {
break
}
total += 1
}
}
}
log.Println("Total files installed: ", total)
return err
}
作者:NeuralProsthesisLa
项目:unloc
func (w *ZipMeta) walk(Zipfile string) error {
var err error
var r *zip.ReadCloser
if r, err = zip.OpenReader(Zipfile); err != nil {
log.Fatalln(err)
return err
}
for _, f := range r.File {
if f.Mode().IsDir() {
w.handleFolder(f.Name)
continue
}
file_name := f.Name
folder_name := ""
folder_index := strings.LastIndex(f.Name, "/")
if folder_index != -1 {
folder_name += file_name[:folder_index] // 4.4.17
if w.isNewFolder(folder_name) {
if err = w.handleFolder(folder_name); err != nil {
return err
}
}
file_name = file_name[folder_index+1:] // strings.Join(dirlist[:len(dirlist)-1]
}
if err = w.handleFile(folder_name, file_name, f); err != nil {
return err
}
}
r.Close()
return nil
}
作者:korbenzhan
项目:xls
// OpenFile() take the name of an XLSX file and returns a populated
// xlsx.File struct for it.
func OpenFile(filename string) (x *File, e error) {
var f *zip.ReadCloser
var error error
var file *File
var v *zip.File
var workbook *zip.File
var sharedStrings *zip.File
var reftable []string
var worksheets map[string]*zip.File
f, error = zip.OpenReader(filename)
var sheetMap map[string]*Sheet
if error != nil {
return nil, error
}
file = new(File)
worksheets = make(map[string]*zip.File, len(f.File))
for _, v = range f.File {
switch v.Name {
case "xl/sharedStrings.xml":
sharedStrings = v
case "xl/workbook.xml":
workbook = v
default:
if len(v.Name) > 12 {
if v.Name[0:13] == "xl/worksheets" {
worksheets[v.Name[14:len(v.Name)-4]] = v
}
}
}
}
file.worksheets = worksheets
reftable, error = readSharedStringsFromZipFile(sharedStrings)
if error != nil {
return nil, error
}
if reftable == nil {
error := new(XLSXReaderError)
error.Err = "No valid sharedStrings.xml found in XLSX file"
return nil, error
}
file.referenceTable = reftable
sheets, names, error := readSheetsFromZipFile(workbook, file)
if error != nil {
return nil, error
}
if sheets == nil {
error := new(XLSXReaderError)
error.Err = "No sheets found in XLSX File"
return nil, error
}
file.Sheets = sheets
sheetMap = make(map[string]*Sheet, len(names))
for i := 0; i < len(names); i++ {
sheetMap[names[i]] = sheets[i]
}
file.Sheet = sheetMap
f.Close()
return file, nil
}
作者:jgalile
项目:webdrive
func writeXpi(xpiPath, extsPath string) error {
var err error
var zr *zip.ReadCloser
var extName string
zr, err = zip.OpenReader(xpiPath)
if err != nil {
return errors.New(cpferr + err.Error())
}
defer zr.Close()
extName, err = readIdFromInstallRdf(zr)
if err != nil {
return err
}
extPath := filepath.Join(extsPath, extName)
err = os.Mkdir(extPath, 0770)
if err != nil {
return errors.New(cpferr + err.Error())
}
for _, f := range zr.File {
if err = writeExtensionFile(f, extPath); err != nil {
return err
}
}
return nil
}
作者:ubs12
项目:ler
func ZipBanner(w http.ResponseWriter, r *http.Request) {
var err error
var rdr *zip.ReadCloser
vars := mux.Vars(r)
// extract zip
rdr, err = zip.OpenReader(vars["file"])
if err != nil {
log.Fatal(err)
}
defer rdr.Close()
// Архив дахь файлуудаар давтаж агуулгыг хэвлэх
for _, f := range rdr.File {
fmt.Printf("'%s' файлын агуулга:\n", f.Name)
/*
folder := conf.Conf["FileHome"] + "/Banner"
filePath := folder + "/" + vars["file"]
if _, e := os.Stat(folder); os.IsNotExist(e) {
err = os.MkdirAll(folder, 0700)
}
rc, err := f.Open()
if err != nil {
log.Fatal(err)
}
defer rc.Close()
d, err := os.Create(filePath)
if err != nil {
return err
}
if _, err := io.Copy(d, s); err != nil {
d.Close()
return err
}
return d.Close()
_, err = io.Copy(os.Stdout, rc)
if err != nil {
log.Fatal(err)
}*/
}
rpc.WriteJson(r, w, "OK", err)
}
作者:yueyon
项目:ninteng
func getBuf(filename string) (buf []byte, suffix string, err error) {
var r *zip.ReadCloser
var rc io.ReadCloser
switch {
case strings.HasSuffix(filename, ".nes") || strings.HasSuffix(filename, ".NES"):
suffix = filename[len(filename)-len(".nes"):]
buf, err = ioutil.ReadFile(filename)
case strings.HasSuffix(filename, ".zip") || strings.HasSuffix(filename, ".ZIP"):
suffix = filename[len(filename)-len(".zip"):]
// Open a zip archive for reading.
r, err = zip.OpenReader(filename)
if err != nil {
return
}
defer r.Close()
// Iterate through the files in the archive,
// printing some of their contents.
for _, f := range r.File {
if !strings.HasSuffix(f.Name, ".nes") && !strings.HasSuffix(f.Name, ".NES") {
continue
}
rc, err = f.Open()
if err != nil {
return
}
buf, err = ioutil.ReadAll(rc)
if err != nil {
return
}
rc.Close()
break
}
default:
err = errors.New("Unknown filetype, must be .nes, .NES, .zip or .ZIP")
}
return
}
作者:janusl
项目:my_recpie
func UnzipFile(name string) error {
var (
err error
file *os.File
rc io.ReadCloser
r *zip.ReadCloser
)
if r, err = zip.OpenReader(name); err != nil {
log.Fatal(err)
return err
}
defer r.Close()
for _, f := range r.File {
fmt.Println(f.Name)
if f.Mode().IsDir() { // if file is a directory
if err = os.MkdirAll(f.Name, f.Mode().Perm()); err != nil {
return err
}
continue
}
if rc, err = f.Open(); err != nil {
return err
}
if file, err = os.Create(f.Name); err != nil {
return err
}
if _, err = io.Copy(file, rc); err != nil {
return err
}
if err = file.Chmod(f.Mode().Perm()); err != nil {
return err
}
file.Close()
rc.Close()
}
return nil
}
作者:duluma
项目:webdrive
// Extracts the name of the extension from within install.rdf
// which is a file contained in webdriver.xpi
func (s *Firefox) extractExtensionName() (extensionName string, err error) {
var zipFile *zip.ReadCloser
var file io.ReadCloser
if _, err = os.Stat(s.Extension.Path); err == nil {
// there is a file named install.rdf within the webdriver extension
// the contents of that file contain the plugin name
// open the zip archive (webdriver extension) and
// extract the contents of of install.rdf to obtain the file name
if zipFile, err = zip.OpenReader(s.Extension.Path); err == nil {
defer zipFile.Close()
for _, f := range zipFile.File {
if extensionName == "" {
if strings.ToLower(f.Name) == "install.rdf" {
if file, err = f.Open(); err == nil {
var buffer []byte
if buffer, err = ioutil.ReadAll(file); err == nil {
manifest := InstallManifest{}
if err = xml.Unmarshal(buffer, &manifest); err == nil {
extensionName = manifest.Description.ID
}
}
file.Close()
}
}
} else {
break
}
}
}
}
return extensionName, err
}
作者:deepzz
项目:go-co
func UnpackZip(filename string, path string) (err error) {
var reader *zip.ReadCloser
if reader, err = zip.OpenReader(filename); err != nil {
return err
}
defer reader.Close()
for _, zipFile := range reader.Reader.File {
filename := sanitizedName(zipFile.Name, path)
if strings.HasSuffix(zipFile.Name, "/") ||
strings.HasSuffix(zipFile.Name, "\\") {
if err = os.MkdirAll(filename, 0755); err != nil {
return err
}
} else {
if err = unpackZippedFile(filename, zipFile); err != nil {
return err
}
}
}
return nil
}
作者:LuxunForeve
项目:Leftwoo
// ReadZip() takes a pointer to a zip.ReadCloser and returns a
// xlsx.File struct populated with its contents. In most cases
// ReadZip is not used directly, but is called internally by OpenFile.
func ReadZip(f *zip.ReadCloser) (*File, error) {
var err error
var file *File
var names []string
var reftable []string
var sharedStrings *zip.File
var sheetMap map[string]*Sheet
var sheetXMLMap map[string]string
var sheets []*Sheet
var style *xlsxStyles
var styles *zip.File
var v *zip.File
var workbook *zip.File
var workbookRels *zip.File
var worksheets map[string]*zip.File
file = new(File)
worksheets = make(map[string]*zip.File, len(f.File))
for _, v = range f.File {
switch v.Name {
case "xl/sharedStrings.xml":
sharedStrings = v
case "xl/workbook.xml":
workbook = v
case "xl/_rels/workbook.xml.rels":
workbookRels = v
case "xl/styles.xml":
styles = v
default:
if len(v.Name) > 14 {
if v.Name[0:13] == "xl/worksheets" {
worksheets[v.Name[14:len(v.Name)-4]] = v
}
}
}
}
sheetXMLMap, err = readWorkbookRelationsFromZipFile(workbookRels)
if err != nil {
return nil, err
}
file.worksheets = worksheets
reftable, err = readSharedStringsFromZipFile(sharedStrings)
if err != nil {
return nil, err
}
if reftable == nil {
readerErr := new(XLSXReaderError)
readerErr.Err = "No valid sharedStrings.xml found in XLSX file"
return nil, readerErr
}
file.referenceTable = reftable
style, err = readStylesFromZipFile(styles)
if err != nil {
return nil, err
}
file.styles = style
sheets, names, err = readSheetsFromZipFile(workbook, file, sheetXMLMap)
if err != nil {
return nil, err
}
if sheets == nil {
readerErr := new(XLSXReaderError)
readerErr.Err = "No sheets found in XLSX File"
return nil, readerErr
}
file.Sheets = sheets
sheetMap = make(map[string]*Sheet, len(names))
for i := 0; i < len(names); i++ {
sheetMap[names[i]] = sheets[i]
}
file.Sheet = sheetMap
f.Close()
return file, nil
}
作者:Richardph
项目:nom
// ReadZip() takes a pointer to a zip.ReadCloser and returns a
// xlsx.File struct populated with its contents. In most cases
// ReadZip is not used directly, but is called internally by OpenFile.
func ReadZip(f *zip.ReadCloser) (*File, error) {
defer f.Close()
return ReadZipReader(&f.Reader)
}
作者:dbratu
项目:impac
func main() {
flag.Parse()
var images []loading.Image
var loadingErrors []loading.Error
if len(*archiveFileName) == 0 {
var pathChan chan string
if len(*imageDirName) > 0 {
if pch, err := getImagePaths(*imageDirName); err == nil {
pathChan = pch
} else {
fmt.Errorf("%s\n", err.Error())
return
}
} else {
pathChan = make(chan string, 10)
go func() {
var line string
for _, err := fmt.Scan(&line); err == nil; _, err = fmt.Scan(&line) {
pathChan <- line
}
pathChan <- ""
}()
}
images, loadingErrors = loading.LoadImages(pathChan)
} else {
var reader *zip.ReadCloser
if r, err := zip.OpenReader(*archiveFileName); err == nil {
reader = r
} else {
fmt.Printf("%s\n", err)
return
}
images, loadingErrors = loading.LoadImagesFromZip(&reader.Reader)
reader.Close()
}
for _, r := range loadingErrors {
fmt.Errorf("Loading of %s failed:\n %s\n", r.Name, r.Message)
}
rects := make([]image.Rectangle, len(images))
for i := 0; i < len(rects); i++ {
rects[i] = images[i].Data.Bounds()
}
union := impack.Arrange(rects)
dest := image.NewNRGBA(image.Rect(0, 0, union.Dx(), union.Dy()))
for i := 0; i < len(rects); i++ {
draw.Draw(dest, rects[i], images[i].Data, image.Pt(0, 0), draw.Src)
}
var out io.Writer
if len(*outputFileName) > 0 {
if f, err := os.Create(*outputFileName); err == nil {
out = f
} else {
fmt.Errorf("%s\n", err)
return
}
} else {
out = os.Stdout
}
png.Encode(out, dest)
}