本文整理汇总了Golang中archive/zip.OpenReader函数的典型用法代码### 示例。如果您正苦于以下问题:Golang OpenReader函数的具体用法?Golang OpenReader怎么用?Golang OpenReader使用的例子?那么恭喜您, 这里精选的函数代码### 示例或许可以为您提供帮助。

在下文中一共展示了OpenReader函数的20个代码### 示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码### 示例。

示例1: main

func main() {
    var output string
    flag.StringVar(&output, "file", "", "Output result to this file")
    flag.Parse()

    if flag.NArg() < 2 {
        webui()
        os.Exit(1)
    } else {
        zip1, err := zip.OpenReader(flag.Arg(0))
        if err != nil {
            log.Fatal(err)
        }
        zip2, err := zip.OpenReader(flag.Arg(1))
        if err != nil {
            log.Fatal(err)
        }
        defer zip1.Close()
        defer zip2.Close()
        result := ZipDiffContent(&zip1.Reader, &zip2.Reader, false, "")
        if output != "" {
            f, err := os.Create(output)
            if err != nil {
                log.Fatal(err)
            }
            defer f.Close()
            DisplayAsText(f, result)
        } else {
            DisplayAsText(os.Stdout, result)
        }
    }
}

开发者ID:anykao,项目名称:p,代码行数:32,代码来源:diffjar.go

示例2: writeData

// Write data to store
func writeData(fn string, nodeID int) (dbTrain, dbTest string) {

    gob.Register(Obs{})

    // Open a zip archive for reading.
    r, err := zip.OpenReader(fn)
    if err != nil {
        glog.Fatalf("can't open zip file %s - error: %s", fn, err)
    }
    defer r.Close()

    // Iterate through the files in the archive,
    for _, f := range r.File {
        fn := path.Base(f.Name)
        if fn == TrainFile {
            glog.Infof("Found %s\n", f.Name)
            dbTrain = writeStore(f, nodeID)
        }
        if fn == TestFile {
            glog.Infof("Found %s\n", f.Name)
            dbTest = writeStore(f, nodeID)
        }
    }
    return
}

开发者ID:theseusyang,项目名称:occult,代码行数:26,代码来源:data.go

示例3: unzip

func unzip(archive, target string) error {

    fmt.Println("Unzip archive ", target)

    reader, err := zip.OpenReader(archive)
    if err != nil {
        return err
    }

    for _, file := range reader.File {
        filePath := filepath.Join(target, file.Name)

        if file.FileInfo().IsDir() {
            os.MkdirAll(filePath, file.Mode())
            continue
        }
        fileReader, err := file.Open()
        if err != nil {
            return err
        }
        defer fileReader.Close()

        targetFile, err := os.OpenFile(filePath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, file.Mode())
        if err != nil {
            return err
        }
        defer targetFile.Close()

        if _, err := io.Copy(targetFile, fileReader); err != nil {
            return err
        }
    }
    return nil
}

开发者ID:urso,项目名称:beats,代码行数:34,代码来源:import_dashboards.go

示例4: main

func main() {
    zipFileName := "test.zip"

    rc, err := zip.OpenReader(zipFileName)
    if err != nil {
        log.Fatal(err)
    }

    zipFiles := rc.File
    for _, zipFile := range zipFiles {
        offset, _ := zipFile.DataOffset()
        log.Println("Compresszed:", zipFile.FileHeader.CompressedSize64, "Uncompressed:", zipFile.FileHeader.UncompressedSize64)
        log.Println(zipFile.FileHeader.Name, "\tDataOffset", offset)

        irc, err := zipFile.Open()
        if err != nil {
            log.Fatal(err)
        }

        if fileContent, err := ioutil.ReadAll(irc); err == nil {
            data := string(fileContent)
            fmt.Print(len(data), "\t", data)
        } else {
            log.Fatal(err)
        }
        irc.Close()
        fmt.Println("----------------------")
    }
}

开发者ID:ericcapricorn,项目名称:GoStandardLibrary-Chinese,代码行数:29,代码来源:example_archive_zip_read_zip_file.go

示例5: TestRandomBrokenParts

func (f *Fuzzy) TestRandomBrokenParts(c *C) {
    if testing.Short() {
        c.Log("This test, tests many versions of an xlsx file and might take a while, it is being skipped")
        c.SucceedNow()
    }
    log.Println("Fuzzy test is using this -test.seed=" + strconv.FormatInt(*randseed, 10))
    rand.Seed(*randseed)
    template, err := zip.OpenReader("./testdocs/testfile.xlsx")
    c.Assert(err, IsNil)
    defer template.Close()

    count := 0

    for brokenFile := range generateBrokenFiles(&template.Reader) {
        count++
        if testing.Verbose() {
            //If the library panics fatally it would be nice to know why
            log.Println("Testing change to ", brokenFile.Name, " on token ", tokenToString(brokenFile.Old), " of type ", reflect.TypeOf(brokenFile.Old), " to ", tokenToString(brokenFile.New))
        }

        if e := Raises(func() { ReadZipReader(brokenFile.File) }); e != nil {

            c.Log("Some file with random changes did raise an exception instead of returning an error", e)
            c.Log("Testing change to ", brokenFile.Name, " on token ", tokenToString(brokenFile.Old), " of type ", reflect.TypeOf(brokenFile.Old), " to ", tokenToString(brokenFile.New))
            c.FailNow()
        }

    }
    c.Succeed()
}

开发者ID:Richardphp,项目名称:noms,代码行数:30,代码来源:fuzzy_test.go

示例6: ExampleReader

func ExampleReader() {
    // Open a zip archive for reading.
    r, err := zip.OpenReader(`c:\xx.zip`)
    if err != nil {
        log.Fatal(err)
    }
    defer r.Close()

    // Iterate through the files in the archive,
    // printing some of their contents.
    for _, f := range r.File {
        fmt.Printf("Contents of %s:\n", f.Name)
        rc, err := f.Open()
        if err != nil {
            fmt.Println("\nopen err:", err)
        }
        _, err = io.CopyN(os.Stdout, rc, 68)
        if err != nil {
            fmt.Println("\ncopy err:", err)
        }
        rc.Close()
        fmt.Println()
    }
    // Output:
    // Contents of README:
    // This is the source code repository for the Go programming language.
}

开发者ID:enderlu,项目名称:vfp,代码行数:27,代码来源:zip1.go

示例7: UnZip

func UnZip(zipFile string) (dirName string, err error) {
    r, err := zip.OpenReader(zipFile)
    if err != nil {
        return
    }

    for _, k := range r.Reader.File {
        if k.FileInfo().IsDir() {
            name := filepath.Join(TMPDIR, k.Name)
            err := os.MkdirAll(name, 0664)
            if err != nil {
                return "", err
            }
            dirName = k.Name
            continue
        }
        r, err := k.Open()
        if err != nil {
            return "", err
        }
        defer r.Close()
        NewFile, err := os.OpenFile(filepath.Join(TMPDIR, k.Name), os.O_TRUNC|os.O_RDWR|os.O_CREATE, 0664)
        if err != nil {
            return "", err
        }
        io.Copy(NewFile, r)
        NewFile.Close()
    }
    return
}

开发者ID:0x9e3779b9,项目名称:golang_lab,代码行数:30,代码来源:main.go

示例8: parseIPA

func parseIPA(path string) (plinfo *plistBundle, err error) {
    plistre := regexp.MustCompile(`^Payload/[^/]*/Info\.plist$`)
    r, err := zip.OpenReader(path)
    if err != nil {
        return
    }
    defer r.Close()

    var plfile *zip.File
    for _, file := range r.File {
        if plistre.MatchString(file.Name) {
            plfile = file
            break
        }
    }
    if plfile == nil {
        err = errors.New("Info.plist file not found")
        return
    }
    plreader, err := plfile.Open()
    if err != nil {
        return
    }
    defer plreader.Close()
    buf := make([]byte, plfile.FileInfo().Size())
    _, err = io.ReadFull(plreader, buf)
    if err != nil {
        return
    }
    dec := goplist.NewDecoder(bytes.NewReader(buf))
    plinfo = new(plistBundle)
    err = dec.Decode(plinfo)
    return
}

开发者ID:RainYang0925,项目名称:gohttpserver,代码行数:34,代码来源:ipa.go

示例9: apiResources

func apiResources() ([]byte, error) {
    p, err := apiJarPath()
    if err != nil {
        return nil, err
    }
    zr, err := zip.OpenReader(p)
    if err != nil {
        return nil, err
    }
    defer zr.Close()

    buf := new(bytes.Buffer)
    for _, f := range zr.File {
        if f.Name == "resources.arsc" {
            rc, err := f.Open()
            if err != nil {
                return nil, err
            }
            _, err = io.Copy(buf, rc)
            if err != nil {
                return nil, err
            }
            rc.Close()
            break
        }
    }
    if buf.Len() == 0 {
        return nil, fmt.Errorf("failed to read resources.arsc")
    }
    return buf.Bytes(), nil
}

开发者ID:leonardyp,项目名称:mobile,代码行数:31,代码来源:sdk.go

示例10: loadAsset

func loadAsset(activity unsafe.Pointer, filename string) (io.Reader, error) {
    apkPath := C.GoString(C.getPackageName((*C.ANativeActivity)(activity)))

    // Open a zip archive for reading.
    r, err := zip.OpenReader(apkPath)
    if err != nil {
        return nil, err
    }
    defer r.Close()

    // Iterate through the files in the archive.
    for _, f := range r.File {
        if f.Name == filename {
            rc, err := f.Open()
            if err != nil {
                return nil, err
            }
            buffer := make([]byte, f.UncompressedSize64)
            _, err = io.ReadFull(rc, buffer)
            if err != nil {
                return nil, err
            }
            rc.Close()
            return bytes.NewBuffer(buffer), nil
        }
    }
    return nil, fmt.Errorf("Resource not found!")
}

开发者ID:kebo,项目名称:gorgasm,代码行数:28,代码来源:asset_android.go

示例11: ReadAPK

// ReadAPK opens the specified APK file 'apk' and walks the contents
// of any DEX files it contains, making callbacks at various points
// through a user-supplied visitor object 'visitor'. See DexApkVisitor
// for more info on which DEX/APK parts are visited.
func ReadAPK(apk string, visitor DexApkVisitor) error {
    rc, err := zip.OpenReader(apk)
    if err != nil {
        return errors.New(fmt.Sprintf("unable to open APK %s: %v", apk, err))
    }
    defer rc.Close()
    z := &rc.Reader

    visitor.VisitAPK(apk)
    visitor.Verbose(1, "APK %s contains %d entries", apk, len(z.File))

    isDex := regexp.MustCompile(`^\S+\.dex$`)
    for i := 0; i < len(z.File); i++ {
        entryName := z.File[i].Name
        if isDex.MatchString(entryName) {
            visitor.Verbose(1, "dex file %s at entry %d", entryName, i)
            reader, err := z.File[i].Open()
            if err != nil {
                return errors.New(fmt.Sprintf("opening apk %s dex %s: %v", apk, entryName, err))
            }
            func() {
                dexread.ReadDEX(&apk, entryName, reader,
                    z.File[i].UncompressedSize64, visitor)
                defer reader.Close()
            }()
        }
    }
    return nil
}

开发者ID:thanm,项目名称:go-read-a-dex,代码行数:33,代码来源:apkread.go

示例12: zipStaticServe

func zipStaticServe(fn string, lastTs time.Time) (*zipHandler, error) {
    zr, err := zip.OpenReader(fn)
    if err != nil {
        return nil, err
    }
    defer zr.Close()

    zf := &zipHandler{
        ts:   lastTs,
        data: map[string][]byte{},
    }

    for _, f := range zr.File {
        rc, err := f.Open()
        if err != nil {
            return nil, err
        }

        d, err := ioutil.ReadAll(rc)
        if err != nil {
            return nil, err
        }
        rc.Close()

        zf.data[f.Name] = d
    }

    return zf, nil
}

开发者ID:steveyen,项目名称:cbgb,代码行数:29,代码来源:zipstatic.go

示例13: Open

// Open an Open Document File, uncompress its ZIP archive,
// and check its mime type. The returned *File provides --
// via its Open method -- access to files containted in the
// ZIP file, like content.xml.
func Open(odfName string) (f *File, err error) {
    of := new(File)
    of.ReadCloser, err = zip.OpenReader(odfName)
    if err != nil {
        return
    }
    mf, err := of.Open("mimetype")
    if err != nil {
        of.Close()
        return
    }
    defer mf.Close()

    b, err := ioutil.ReadAll(mf)
    if err != nil {
        return
    }
    of.MimeType = string(b)

    if !strings.HasPrefix(of.MimeType, MimeTypePfx) {
        err = errors.New("not an Open Document mime type")
    } else {
        f = of
    }

    return
}

开发者ID:knieriem,项目名称:odf,代码行数:31,代码来源:read.go

示例14: main

func main() {
    reader, err := zip.OpenReader("output/sample.zip")
    if err != nil {
        log.Fatalln(err)
    }
    defer reader.Close()

    var rc io.ReadCloser
    for _, f := range reader.File {
        rc, err = f.Open()
        if err != nil {
            log.Fatal(err)
        }

        buf := new(bytes.Buffer)
        _, err = io.Copy(buf, rc)
        if err != nil {
            log.Fatal(err)
        }
        if err = ioutil.WriteFile("output/"+f.Name, buf.Bytes(), 0755); err != nil {
            log.Fatal(err)
        }
        rc.Close()
    }
}

开发者ID:qt-luigi,项目名称:golangcafe,代码行数:25,代码来源:readzip.go

示例15: UnzipFile

func UnzipFile(src, dest, fileName string) error {
    zipReader, err := zip.OpenReader(src)
    if err != nil {
        return err
    }
    defer func() error {
        if err := zipReader.Close(); err != nil {
            return fmt.Errorf("Error unzipping: (%s) %v", src, err)
        }

        return nil
    }()

    for _, zf := range zipReader.File {
        if zf.Name != fileName {
            continue
        }

        dst, err := os.Create(dest)
        if err != nil {
            return err
        }

        defer dst.Close()
        src, err := zf.Open()
        if err != nil {
            // err
        }
        defer src.Close()

        io.Copy(dst, src)
    }

    return nil
}

开发者ID:infoassure,项目名称:nsrls,代码行数:35,代码来源:file.go

示例16: ExtractZipFile

func ExtractZipFile(src string, dest string) error {
    if !strings.HasSuffix(dest, pathutil.SLASH) {
        dest += pathutil.SLASH
    }
    rc, err := zip.OpenReader(src)
    if err != nil {
        return err
    }
    defer rc.Close()

    for _, zf := range rc.Reader.File {
        name := zf.Name
        mode := zf.Mode()
        if mode.IsDir() {
            os.MkdirAll(dest+name, zf.Mode())
        } else {
            parent_path := pathutil.ParentPath(dest + name)
            os.MkdirAll(parent_path, pathutil.DEFAULT_DIR_ACCESS)
            if err := unpackZippedFile(dest, name, zf); err != nil {
                return err
            }
            os.Chmod(dest+name, mode)
        }
    }

    return nil
}

开发者ID:jsli,项目名称:gtbox,代码行数:27,代码来源:zip.go

示例17: parseIpaIcon

func parseIpaIcon(path string) (data []byte, err error) {
    iconPattern := regexp.MustCompile(`(?i)^Payload/[^/]*/icon\.png$`)
    r, err := zip.OpenReader(path)
    if err != nil {
        return
    }
    defer r.Close()

    var zfile *zip.File
    for _, file := range r.File {
        if iconPattern.MatchString(file.Name) {
            zfile = file
            break
        }
    }
    if zfile == nil {
        err = errors.New("icon.png file not found")
        return
    }
    plreader, err := zfile.Open()
    if err != nil {
        return
    }
    defer plreader.Close()
    return ioutil.ReadAll(plreader)
}

开发者ID:RainYang0925,项目名称:gohttpserver,代码行数:26,代码来源:ipa.go

示例18: unzip

func unzip(src string, dest string) error {
    zipReader, err := zip.OpenReader(src)
    if err != nil {
        return err
    }
    defer zipReader.Close()

    os.MkdirAll(dest, 0755)
    for _, file := range zipReader.File {
        reader, err := file.Open()
        if err != nil {
            return err
        }
        defer reader.Close()

        path := filepath.Join(dest, file.Name)
        if file.FileInfo().IsDir() {
            os.MkdirAll(path, file.Mode())
        } else {
            file, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, file.Mode())
            if err != nil {
                return err
            }

            _, err = io.Copy(file, reader)
            if err != nil {
                return err
            }
            file.Close()
        }
    }

    return nil
}

开发者ID:rootwzrd,项目名称:appstax-cli,代码行数:34,代码来源:download.go

示例19: Unzip

//export Unzip
func Unzip(zipname *C.char) int32 {
    r, err := zip.OpenReader(C.GoString(zipname))
    if err != nil {
        log.Println(err)
        return -1
    }
    defer r.Close()

    // Iterate through the files in the archive,
    for _, file := range r.File {
        ri, err := file.Open()
        if err != nil {
            log.Println(err)
            return -1
        }
        defer ri.Close()

        wi, err := os.Create(file.Name)
        if err != nil {
            log.Println(err)
            return -1
        }
        defer wi.Close()

        _, err = io.Copy(wi, ri)
        if err != nil {
            log.Println(err)
            return -1
        }
    }

    return 0
}

开发者ID:kuba–,项目名称:c-go-zip,代码行数:34,代码来源:zip.go

示例20: Unzip

func Unzip(src string) string {
    var fileName string
    r, err := zip.OpenReader(src)
    if err != nil {
        panic(err)
    }
    defer r.Close()

    for _, f := range r.File {
        if f.Name == "ngrok" {
            fileName = f.Name
            rc, err := f.Open()
            if err != nil {
                panic(err)
            }
            defer rc.Close()

            f, err := os.OpenFile(
                f.Name, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, f.Mode())
            if err != nil {
                panic(err)
            }
            defer f.Close()

            _, err = io.Copy(f, rc)
            if err != nil {
                panic(err)
            }
        }
    }

    return fileName
}

开发者ID:mehmetg,项目名称:prerunserver,代码行数:33,代码来源:Utilities.go

最后编辑: goerone  文档更新时间: 2021-08-23 19:14   作者:goerone