本文整理匯總了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
}
示例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
}
示例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))
}
示例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))
})
}
示例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
}
示例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))
}
}
示例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)
})
}
示例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
}
示例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() {