本文整理汇总了Golang中github.com/cloudfoundry/gofileutils/fileutils.CopyPathToWriter函数的典型用法代码示例。如果您正苦于以下问题:Golang CopyPathToWriter函数的具体用法?Golang CopyPathToWriter怎么用?Golang CopyPathToWriter使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了CopyPathToWriter函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: AppFilesInDir
func AppFilesInDir(dir string) (appFiles []models.AppFileFields, err error) {
dir, err = filepath.Abs(dir)
if err != nil {
return
}
err = WalkAppFiles(dir, func(fileName string, fullPath string) (err error) {
fileInfo, err := os.Lstat(fullPath)
if err != nil {
return
}
appFile := models.AppFileFields{
Path: filepath.ToSlash(fileName),
Size: fileInfo.Size(),
}
if fileInfo.IsDir() {
appFile.Sha1 = "0"
appFile.Size = 0
} else {
hash := sha1.New()
err = fileutils.CopyPathToWriter(fullPath, hash)
if err != nil {
return
}
appFile.Sha1 = fmt.Sprintf("%x", hash.Sum(nil))
}
appFiles = append(appFiles, appFile)
return
})
return
}
开发者ID:Jack1996,项目名称:cli,代码行数:34,代码来源:app_files.go
示例2: copyPathToPath
func copyPathToPath(fromPath, toPath string) (err error) {
srcFileInfo, err := os.Stat(fromPath)
if err != nil {
return
}
if srcFileInfo.IsDir() {
err = os.MkdirAll(toPath, srcFileInfo.Mode())
if err != nil {
return
}
} else {
var dst *os.File
dst, err = fileutils.Create(toPath)
if err != nil {
return
}
defer dst.Close()
dst.Chmod(srcFileInfo.Mode())
err = fileutils.CopyPathToWriter(fromPath, dst)
}
return err
}
开发者ID:Jack1996,项目名称:cli,代码行数:25,代码来源:app_files.go
示例3: sha
func sha(path string) string {
hash := sha1.New()
err := fileutils.CopyPathToWriter(path, hash)
if err != nil {
panic("Failed to compute sha1")
}
return fmt.Sprintf("%x", hash.Sum(nil))
}
开发者ID:glyn,项目名称:bloblets,代码行数:8,代码来源:abserver.go
示例4: Write
func (b *bloblet) Write(w io.Writer) {
fileutils.TempDir("bloblet-zipdir", func(zipDir string, err error) {
cliutil.Check(err)
zipPath := filepath.Join(zipDir, BlobletFileName)
cliutil.Check(b.Compress(zipPath))
cliutil.Check(fileutils.CopyPathToWriter(zipPath, w))
})
}
开发者ID:glyn,项目名称:bloblets,代码行数:8,代码来源:bloblet.go
示例5: Zip
func (zipper ApplicationZipper) Zip(dirOrZipFile string, targetFile *os.File) (err error) {
if zipper.IsZipFile(dirOrZipFile) {
err = fileutils.CopyPathToWriter(dirOrZipFile, targetFile)
} else {
err = writeZipFile(dirOrZipFile, targetFile)
}
targetFile.Seek(0, os.SEEK_SET)
return
}
开发者ID:nota-ja,项目名称:cli,代码行数:9,代码来源:zipper.go
示例6: New
// New returns a Hash of the contents of the specified file.
func New(filePath string) Hash {
fileInfo, err := os.Lstat(filePath)
if err != nil {
panic(err)
}
if fileInfo.IsDir() {
panic("cannot compute hash of directory")
} else {
hash := sha1.New()
err = fileutils.CopyPathToWriter(filePath, hash)
if err != nil {
panic(err)
}
return Hash(hash.Sum(nil))
}
}
开发者ID:glyn,项目名称:bloblets,代码行数:18,代码来源:filehash.go
示例7: writeZipFile
func writeZipFile(dir string, targetFile *os.File) error {
isEmpty, err := fileutils.IsDirEmpty(dir)
if err != nil {
return err
}
if isEmpty {
return errors.NewEmptyDirError(dir)
}
writer := zip.NewWriter(targetFile)
defer writer.Close()
appfiles := ApplicationFiles{}
return appfiles.WalkAppFiles(dir, func(fileName string, fullPath string) error {
fileInfo, err := os.Stat(fullPath)
if err != nil {
return err
}
header, err := zip.FileInfoHeader(fileInfo)
if err != nil {
return err
}
header.Name = filepath.ToSlash(fileName)
if fileInfo.IsDir() {
header.Name += "/"
}
zipFilePart, err := writer.CreateHeader(header)
if err != nil {
return err
}
if fileInfo.IsDir() {
return nil
}
return fileutils.CopyPathToWriter(fullPath, zipFilePart)
})
}
开发者ID:riccardomc,项目名称:cf-fastpush-plugin,代码行数:43,代码来源:zipper.go
示例8: Compress
func (b *bloblet) Compress(path string) error {
f, err := os.OpenFile(path, os.O_CREATE+os.O_RDWR, 0644)
if err != nil {
return err
}
defer f.Close()
zw := zip.NewWriter(f)
defer zw.Close()
for filePath, _ := range b.files {
w, err := zw.Create(filePath)
if err != nil {
return err
}
err = fileutils.CopyPathToWriter(filePath, w)
if err != nil {
return err
}
}
return nil
}
开发者ID:glyn,项目名称:bloblets,代码行数:21,代码来源:bloblet.go
示例9:
Expect(fileInfo.Mode()).To(Equal(expectedFileInfo.Mode()))
})
})
})
Describe("CopyPathToWriter", func() {
var destPath string
BeforeEach(func() {
destFile, err := ioutil.TempFile("", "copy_test")
Expect(err).NotTo(HaveOccurred())
defer destFile.Close()
destPath = destFile.Name()
err = fileutils.CopyPathToWriter(fixturePath, destFile)
Expect(err).NotTo(HaveOccurred())
})
It("copies the file contents", func() {
fileBytes, err := ioutil.ReadFile(destPath)
Expect(err).NotTo(HaveOccurred())
Expect(fileBytes).To(Equal(fixtureBytes))
})
})
Describe("CopyReaderToPath", func() {
var destPath = fileutils.TempPath("copy_test")
BeforeEach(func() {
开发者ID:hail100,项目名称:cli,代码行数:31,代码来源:file_utils_test.go
注:本文中的github.com/cloudfoundry/gofileutils/fileutils.CopyPathToWriter函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论