本文整理汇总了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))
}