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

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

示例1: StreamFile

// StreamFile streams a file or directory entry into StreamArchive.
func (s *StreamArchive) StreamFile(relPath string, fi os.FileInfo, data []byte) error {
    if fi.IsDir() {
        fh, err := zip.FileInfoHeader(fi)
        if err != nil {
            return err
        }
        fh.Name = relPath + "/"
        if _, err = s.Writer.CreateHeader(fh); err != nil {
            return err
        }
    } else {
        fh, err := zip.FileInfoHeader(fi)
        if err != nil {
            return err
        }
        fh.Name = filepath.Join(relPath, fi.Name())
        fh.Method = zip.Deflate
        fw, err := s.Writer.CreateHeader(fh)
        if err != nil {
            return err
        } else if _, err = fw.Write(data); err != nil {
            return err
        }
    }
    return nil
}

开发者ID:RouGang,项目名称:gopm,代码行数:27,代码来源:stream.go

示例2: addFileToZIP

func addFileToZIP(zw *zip.Writer, item ArchiveItem) error {
    //fmt.Printf("Adding %s\n", item.FileSystemPath)
    binfo, err := os.Stat(item.FileSystemPath)
    if err != nil {
        return err
    }
    if binfo.IsDir() {
        header, err := zip.FileInfoHeader(binfo)
        if err != nil {
            return err
        }
        header.Method = zip.Deflate
        header.Name = item.ArchivePath
        _, err = zw.CreateHeader(header)
        if err != nil {
            return err
        }
        file, err := os.Open(item.FileSystemPath)
        if err != nil {
            return err
        }
        fis, err := file.Readdir(0)
        for _, fi := range fis {
            err = addFileToZIP(zw, ArchiveItem{filepath.Join(item.FileSystemPath, fi.Name()), filepath.Join(item.ArchivePath, fi.Name()), nil})
            if err != nil {
                return err
            }
        }
    } else {
        header, err := zip.FileInfoHeader(binfo)
        if err != nil {
            return err
        }
        header.Method = zip.Deflate
        header.Name = item.ArchivePath
        w, err := zw.CreateHeader(header)
        if err != nil {
            return err
        }
        bf, err := os.Open(item.FileSystemPath)
        if err != nil {
            return err
        }
        defer bf.Close()
        _, err = io.Copy(w, bf)
        if err != nil {
            return err
        }
    }
    return err
}

开发者ID:ngpestelos,项目名称:someutils,代码行数:51,代码来源:zip.go

示例3: addKeysToArchive

func addKeysToArchive(zipWriter *zip.Writer, newKeyStore *trustmanager.KeyFileStore, tempBaseDir string) error {
    // List all files but no symlinks
    for _, fullKeyPath := range newKeyStore.ListFiles(false) {
        relKeyPath := strings.TrimPrefix(fullKeyPath, tempBaseDir)
        relKeyPath = strings.TrimPrefix(relKeyPath, string(filepath.Separator))

        fi, err := os.Stat(fullKeyPath)
        if err != nil {
            return err
        }

        infoHeader, err := zip.FileInfoHeader(fi)
        if err != nil {
            return err
        }

        infoHeader.Name = relKeyPath
        zipFileEntryWriter, err := zipWriter.CreateHeader(infoHeader)
        if err != nil {
            return err
        }

        fileContents, err := ioutil.ReadFile(fullKeyPath)
        if err != nil {
            return err
        }
        if _, err = zipFileEntryWriter.Write(fileContents); err != nil {
            return err
        }
    }

    return nil
}

开发者ID:RichardScothern,项目名称:notary,代码行数:33,代码来源:import_export.go

示例4: addFileToZip

func addFileToZip(w *zip.Writer, path string, newname string) error {
    f, err := os.Open(path)
    if err != nil {
        return err
    }
    info, err := f.Stat()
    if err != nil {
        return err
    }
    header, err := zip.FileInfoHeader(info)
    if err != nil {
        return err
    }
    if newname != "" {
        header.Name = newname
    }
    wr, err := w.CreateHeader(header)
    if err != nil {
        return err
    }
    fileBytes, err := ioutil.ReadFile(path)
    if err != nil {
        return err
    }
    _, err = wr.Write(fileBytes)
    if err != nil {
        return err
    }
    return nil
}

开发者ID:maxmcd,项目名称:gitbao,代码行数:30,代码来源:builder.go

示例5: addHandlerToZip

func addHandlerToZip(w *zip.Writer, bf baofile.Baofile) error {
    path := "lambda/handler_example.js"
    f, err := os.Open(path)
    if err != nil {
        return err
    }
    info, err := f.Stat()
    if err != nil {
        return err
    }
    header, err := zip.FileInfoHeader(info)
    if err != nil {
        return err
    }
    wr, err := w.CreateHeader(header)
    if err != nil {
        return err
    }
    fileBytes, err := ioutil.ReadFile(path)
    if err != nil {
        return err
    }

    handlerTemplate := string(fileBytes)
    t := template.Must(template.New("handler").Parse(handlerTemplate))
    err = t.Execute(wr, bf)
    if err != nil {
        return err
    }
    return nil
}

开发者ID:maxmcd,项目名称:gitbao,代码行数:31,代码来源:builder.go

示例6: compress

func (wft *zipWalk) compress(name, fpath string, fi os.FileInfo) (bool, error) {
    isSym := fi.Mode()&os.ModeSymlink > 0
    if isSym {
        // golang1.1 doesn't support embed symlink
        // what i miss something?
        return false, nil
    }

    hdr, err := zip.FileInfoHeader(fi)
    if err != nil {
        return false, err
    }
    hdr.Name = name

    zw := wft.zw
    w, err := zw.CreateHeader(hdr)
    if err != nil {
        return false, err
    }

    if isSym == false {
        fr, err := os.Open(fpath)
        if err != nil {
            return false, err
        }
        defer fr.Close()
        _, err = io.Copy(w, fr)
        if err != nil {
            return false, err
        }
    }

    return true, nil
}

开发者ID:krasnoukhov,项目名称:bee,代码行数:34,代码来源:pack.go

示例7: Walk

func (z *zipRenderer) Walk(path string, finfo os.FileInfo, err error) error {
    if err != nil {
        return err
    }

    if finfo.IsDir() {
        return nil
    }

    fh, err := zip.FileInfoHeader(finfo)
    if err != nil {
        return err
    }

    fh.Name = "download/" + path
    w, err := z.w.CreateHeader(fh)
    if err != nil {
        return err
    }

    f, err := os.Open(filepath.Join(z.root, path))
    if err != nil {
        return err
    }
    defer f.Close()

    _, err = io.Copy(w, f)
    return err
}

开发者ID:jonathanwei,项目名称:fproxy,代码行数:29,代码来源:ziprenderer.go

示例8: addKeysToArchive

func addKeysToArchive(zipWriter *zip.Writer, newKeyStore *trustmanager.KeyFileStore) error {
    for _, relKeyPath := range newKeyStore.ListFiles() {
        fullKeyPath := filepath.Join(newKeyStore.BaseDir(), relKeyPath)

        fi, err := os.Lstat(fullKeyPath)
        if err != nil {
            return err
        }

        infoHeader, err := zip.FileInfoHeader(fi)
        if err != nil {
            return err
        }

        infoHeader.Name = relKeyPath

        zipFileEntryWriter, err := zipWriter.CreateHeader(infoHeader)
        if err != nil {
            return err
        }

        fileContents, err := ioutil.ReadFile(fullKeyPath)
        if err != nil {
            return err
        }

        if _, err = zipFileEntryWriter.Write(fileContents); err != nil {
            return err
        }
    }

    return nil
}

开发者ID:DaveDaCoda,项目名称:docker,代码行数:33,代码来源:import_export.go

示例9: createZipEntry

func createZipEntry(archive *zip.Writer, fileName string) error {
    fi, err := os.Lstat(fileName)
    if err != nil {
        logrus.Warningln("File ignored:", err)
        return nil
    }

    fh, err := zip.FileInfoHeader(fi)
    if err != nil {
        return err
    }
    fh.Name = fileName
    fh.Extra = createZipExtra(fi)

    switch fi.Mode() & os.ModeType {
    case os.ModeDir:
        return createZipDirectoryEntry(archive, fh)

    case os.ModeSymlink:
        return createZipSymlinkEntry(archive, fh)

    case os.ModeNamedPipe, os.ModeSocket, os.ModeDevice:
        // Ignore the files that of these types
        logrus.Warningln("File ignored:", fileName)
        return nil

    default:
        return createZipFileEntry(archive, fh)
    }
}

开发者ID:bssthu,项目名称:gitlab-ci-multi-runner,代码行数:30,代码来源:zip_create.go

示例10: writeFileToZip

func writeFileToZip(zipper *zip.Writer, filename string) error {
    file, err := os.Open(filename)

    if err != nil {
        return err
    }

    defer file.Close()

    info, err := file.Stat()

    if err != nil {
        return err
    }

    header, err := zip.FileInfoHeader(info)

    if err != nil {
        return err
    }

    header.Name = helper.SanitizedName(filename)

    writer, err := zipper.CreateHeader(header)

    if err != nil {
        return err
    }

    _, err = io.Copy(writer, file)

    return err
}

开发者ID:herksaw,项目名称:gompress,代码行数:33,代码来源:zip.go

示例11: AddEntry

func (z *ZipFile) AddEntry(path, name string) error {
    fi, err := os.Stat(name)
    if err != nil {
        return err
    }

    fh, err := zip.FileInfoHeader(fi)
    if err != nil {
        return err
    }

    fh.Name = path
    fh.Method = zip.Deflate // data compression algorithm

    entry, err := z.writer.CreateHeader(fh)
    if err != nil {
        return err
    }

    if fi.IsDir() {
        return nil
    }

    file, err := os.Open(name)
    if err != nil {
        return err
    }
    defer file.Close()

    _, err = io.Copy(entry, file)

    return err
}

开发者ID:gansidui,项目名称:ziputil,代码行数:33,代码来源:ziputil.go

示例12: addZip

func addZip(filename, buildDir string, zipWriter *zip.Writer) error {
    zipfile, err := os.Open(filename)
    if err != nil {
        return err
    }
    defer zipfile.Close()

    info, err := zipfile.Stat()
    if err != nil {
        return err
    }

    header, err := zip.FileInfoHeader(info)
    if err != nil {
        return err
    }

    r := regexp.MustCompile(buildDir + "/")
    header.Name = r.ReplaceAllString(filename, "")
    writer, err := zipWriter.CreateHeader(header)
    if err != nil {
        return err
    }

    _, err = io.Copy(writer, zipfile)
    return nil
}

开发者ID:gophergala2016,项目名称:sisho,代码行数:27,代码来源:epubify.go

示例13: foliazipdir

func foliazipdir(q *Context, zf *zip.Writer, fdir, subdir string) (ok bool) {
    dir := filepath.Join(fdir, subdir)
    files, err := ioutil.ReadDir(dir)
    if foliaErr(q, err) {
        return false
    }
    for _, file := range files {
        fname := path.Join(subdir, file.Name()) // in zip alleen forward slashes toegestaan
        if file.IsDir() {
            if !foliazipdir(q, zf, fdir, fname) {
                return false
            }
        } else {
            data, err := ioutil.ReadFile(filepath.Join(fdir, fname))
            if foliaErr(q, err) {
                return false
            }
            fh, err := zip.FileInfoHeader(file)
            if foliaErr(q, err) {
                return false
            }
            fh.Name = fname
            f, err := zf.CreateHeader(fh)
            if foliaErr(q, err) {
                return false
            }
            _, err = f.Write(data)
            if foliaErr(q, err) {
                return false
            }
        }
    }
    return true
}

开发者ID:rug-compling,项目名称:paqu,代码行数:34,代码来源:foliatool.go

示例14: addFileToZIP

func addFileToZIP(zw *zip.Writer, item ArchiveItem) (err error) {
    binfo, err := os.Stat(item.FileSystemPath)
    if err != nil {
        return
    }
    header, err := zip.FileInfoHeader(binfo)
    if err != nil {
        return
    }
    header.Method = zip.Deflate
    //always use forward slashes even on Windows
    header.Name = strings.Replace(item.ArchivePath, "\\", "/", -1)
    w, err := zw.CreateHeader(header)
    if err != nil {
        zw.Close()
        return
    }
    bf, err := os.Open(item.FileSystemPath)
    if err != nil {
        return
    }
    defer bf.Close()
    _, err = io.Copy(w, bf)
    return
}

开发者ID:kc87654321,项目名称:goxc,代码行数:25,代码来源:zip.go

示例15: addFileToZip

func addFileToZip(zipWriter *zip.Writer, fi os.FileInfo, srcPath string) error {
    fh, err := zip.FileInfoHeader(fi)
    if err != nil {
        return err
    }
    fh.Method = zip.Deflate
    destFile, err := zipWriter.CreateHeader(fh)
    if err != nil {
        return err
    }

    srcFile, err := os.Open(srcPath)
    if err != nil {
        return err
    }
    defer srcFile.Close()

    ba, err := ioutil.ReadAll(srcFile)
    if err != nil {
        return err
    }

    //_, err = io.Copy(destFile, srcFile)
    _, err = destFile.Write(ba)
    return err
}

开发者ID:jquag,项目名称:kempt,代码行数:26,代码来源:util.go

示例16: addFile

// Add file to zip.
func (z *Zipper) addFile(filePath string) error {
    // Get file information.
    fileInfo, err := os.Stat(filePath)
    if err != nil {
        return err
    }
    // Get file content.
    content, err := ioutil.ReadFile(filePath)
    if err != nil {
        return err
    }
    // Set zip header.
    header, _ := zip.FileInfoHeader(fileInfo)
    path := filepath.Join(z.basePath, filePath)
    header.Name = path
    zipFile, err := z.writer.CreateHeader(header)
    if err != nil {
        return err
    }
    // Write content.
    _, err = zipFile.Write(content)
    if err != nil {
        return err
    }
    return nil
}

开发者ID:srtkkou,项目名称:zgok,代码行数:27,代码来源:zipper.go

示例17: writeZipFile

func writeZipFile(dir string, targetFile *os.File) (err error) {
    isEmpty, err := fileutils.IsDirEmpty(dir)
    if err != nil {
        return
    }
    if isEmpty {
        err = errors.New("Directory is empty")
        return
    }

    writer := zip.NewWriter(targetFile)
    defer writer.Close()

    err = WalkAppFiles(dir, func(fileName string, fullPath string) (err error) {
        fileInfo, err := os.Stat(fullPath)
        if err != nil {
            return err
        }

        header, err := zip.FileInfoHeader(fileInfo)
        header.Name = filepath.ToSlash(fileName)
        if err != nil {
            return err
        }

        zipFilePart, err := writer.CreateHeader(header)
        err = fileutils.CopyPathToWriter(fullPath, zipFilePart)
        return
    })

    return
}

开发者ID:rodney-vin,项目名称:cli,代码行数:32,代码来源:zipper.go

示例18: addKeysToArchive

func addKeysToArchive(zipWriter *zip.Writer, newKeyStore *trustmanager.KeyFileStore, subDir string) error {
    // List all files but no symlinks
    for _, relKeyPath := range newKeyStore.ListFiles(false) {
        fullKeyPath := filepath.Join(newKeyStore.BaseDir(), relKeyPath)

        fi, err := os.Stat(fullKeyPath)
        if err != nil {
            return err
        }

        infoHeader, err := zip.FileInfoHeader(fi)
        if err != nil {
            return err
        }

        infoHeader.Name = filepath.Join(subDir, relKeyPath)
        zipFileEntryWriter, err := zipWriter.CreateHeader(infoHeader)
        if err != nil {
            return err
        }

        fileContents, err := ioutil.ReadFile(fullKeyPath)
        if err != nil {
            return err
        }
        if _, err = zipFileEntryWriter.Write(fileContents); err != nil {
            return err
        }
    }

    return nil
}

开发者ID:ChanderG,项目名称:docker,代码行数:32,代码来源:import_export.go

示例19: writeFileToZip

// 逐个文件,写入zip包
// zipper *zip.Writer:要写入的zip包的zip.Writer
// includeFileName string:本次写入的文件的全路径+名字
func writeFileToZip(zipper *zip.Writer, includeFileName string) error {
    //打开待写入文件
    includeFile, err := os.Open(includeFileName)
    if err != nil {
        return err
    }
    defer includeFile.Close()

    //获取文件描述
    includeFileInfo, err := includeFile.Stat()
    if err != nil {
        return err
    }

    //zip.FileInfoHeader
    zipFileHeader, err := zip.FileInfoHeader(includeFileInfo)
    if err != nil {
        return err
    }

    //修改文件描述的Header,截断路径,只保留文件名
    //否则,解压的时候,可能按压缩进来时候的文件路径来解压,解压回到原来的位置,而不是当前目录
    zipFileHeader.Name = path.Base(includeFileName)

    //用zip.FileInfoHeader,创建zip包内的一个项,并获得io.Writer,准备写入文件
    zipFileWriter, err := zipper.CreateHeader(zipFileHeader)
    if err != nil {
        return err
    }

    //写入本次的文件
    _, err = io.Copy(zipFileWriter, includeFile)
    return err
}

开发者ID:TYuenCN,项目名称:TYGo,代码行数:37,代码来源:compress.go

示例20: TestProcessZipExtra

func TestProcessZipExtra(t *testing.T) {
    testFile, err := ioutil.TempFile("", "test")
    assert.NoError(t, err)
    defer testFile.Close()
    defer os.Remove(testFile.Name())

    fi, _ := testFile.Stat()
    assert.NotNil(t, fi)

    zipFile, err := zip.FileInfoHeader(fi)
    assert.NoError(t, err)
    zipFile.Extra = createZipExtra(fi)

    err = ioutil.WriteFile(fi.Name(), []byte{}, 0666)
    defer os.Remove(fi.Name())
    assert.NoError(t, err)

    err = processZipExtra(zipFile)
    assert.NoError(t, err)

    fi2, _ := testFile.Stat()
    assert.NotNil(t, fi2)
    assert.Equal(t, fi.Mode(), fi2.Mode())
    assert.Equal(t, fi.ModTime(), fi2.ModTime())
}

开发者ID:bssthu,项目名称:gitlab-ci-multi-runner,代码行数:25,代码来源:zip_extra_test.go

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