本文整理匯總了Golang中github.com/ipfs/go-ipfs/commands/files.NewSerialFile函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewSerialFile函數的具體用法?Golang NewSerialFile怎麽用?Golang NewSerialFile使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewSerialFile函數的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: appendFile
func appendFile(args []files.File, inputs []string, argDef *cmds.Argument, recursive bool) ([]files.File, []string, error) {
fpath := inputs[0]
if fpath == "." {
cwd, err := os.Getwd()
if err != nil {
return nil, nil, err
}
fpath = cwd
}
stat, err := os.Lstat(fpath)
if err != nil {
return nil, nil, err
}
if stat.IsDir() {
if !argDef.Recursive {
err = fmt.Errorf("Invalid path '%s', argument '%s' does not support directories",
fpath, argDef.Name)
return nil, nil, err
}
if !recursive {
err = fmt.Errorf("'%s' is a directory, use the '-%s' flag to specify directories",
fpath, cmds.RecShort)
return nil, nil, err
}
}
arg, err := files.NewSerialFile(path.Base(fpath), fpath, stat)
if err != nil {
return nil, nil, err
}
return append(args, arg), inputs[1:], nil
}
示例2: appendFile
func appendFile(fpath string, argDef *cmds.Argument, recursive, hidden bool) (files.File, error) {
fpath = filepath.ToSlash(filepath.Clean(fpath))
if fpath == "." {
cwd, err := os.Getwd()
if err != nil {
return nil, err
}
fpath = cwd
}
stat, err := os.Lstat(fpath)
if err != nil {
return nil, err
}
if stat.IsDir() {
if !argDef.Recursive {
return nil, fmt.Errorf(dirNotSupportedFmtStr, fpath, argDef.Name)
}
if !recursive {
return nil, fmt.Errorf(notRecursiveFmtStr, fpath, cmds.RecShort)
}
}
return files.NewSerialFile(path.Base(fpath), fpath, hidden, stat)
}
示例3: AddR
// AddR recursively adds files in |path|.
func AddR(n *core.IpfsNode, root string) (key string, err error) {
n.Blockstore.PinLock().Unlock()
stat, err := os.Lstat(root)
if err != nil {
return "", err
}
f, err := files.NewSerialFile(root, root, false, stat)
if err != nil {
return "", err
}
defer f.Close()
fileAdder, err := NewAdder(n.Context(), n.Pinning, n.Blockstore, n.DAG)
if err != nil {
return "", err
}
err = fileAdder.addFile(f)
if err != nil {
return "", err
}
nd, err := fileAdder.Finalize()
if err != nil {
return "", err
}
return nd.String(), nil
}
示例4: AddR
// AddR recursively adds files in |path|.
func AddR(n *core.IpfsNode, root string) (key string, err error) {
stat, err := os.Lstat(root)
if err != nil {
return "", err
}
f, err := files.NewSerialFile(root, root, stat)
if err != nil {
return "", err
}
defer f.Close()
dagnode, err := addFile(n, f)
if err != nil {
return "", err
}
k, err := dagnode.Key()
if err != nil {
return "", err
}
n.Pinning.GetManual().RemovePinWithMode(k, pin.Indirect)
if err := n.Pinning.Flush(); err != nil {
return "", err
}
return k.String(), nil
}
示例5: BuildDagFromFile
// Builds a DAG from the given file, writing created blocks to disk as they are
// created
func BuildDagFromFile(fpath string, ds dag.DAGService) (*dag.Node, error) {
stat, err := os.Lstat(fpath)
if err != nil {
return nil, err
}
if stat.IsDir() {
return nil, fmt.Errorf("`%s` is a directory", fpath)
}
f, err := files.NewSerialFile(fpath, fpath, false, stat)
if err != nil {
return nil, err
}
defer f.Close()
return BuildDagFromReader(ds, chunk.NewSizeSplitter(f, chunk.DefaultBlockSize))
}