1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-07-24 02:39:25 +08:00
Files
kubo/commands/files/file.go
Kevin Atkinson 73f9a90cbf Create a FilestoreNode object to carry PosInfo
When doing a filestore add, we wrap whatever nodes we create in a
FilestoreNode object and add the PosInfo to it so that the filestore
will be able to extract information as needed.

Edited by whyrusleeping

License: MIT
Signed-off-by: Kevin Atkinson <k@kevina.org>
2016-10-24 16:30:45 -04:00

63 lines
1.5 KiB
Go

package files
import (
"errors"
"io"
"os"
)
var (
ErrNotDirectory = errors.New("Couldn't call NextFile(), this isn't a directory")
ErrNotReader = errors.New("This file is a directory, can't use Reader functions")
)
// File is an interface that provides functionality for handling
// files/directories as values that can be supplied to commands. For
// directories, child files are accessed serially by calling `NextFile()`.
type File interface {
// Files implement ReadCloser, but can only be read from or closed if
// they are not directories
io.ReadCloser
// FileName returns a filename path associated with this file
FileName() string
// FullPath returns the full path in the os associated with this file
FullPath() string
// IsDirectory returns true if the File is a directory (and therefore
// supports calling `NextFile`) and false if the File is a normal file
// (and therefor supports calling `Read` and `Close`)
IsDirectory() bool
// NextFile returns the next child file available (if the File is a
// directory). It will return (nil, io.EOF) if no more files are
// available. If the file is a regular file (not a directory), NextFile
// will return a non-nil error.
NextFile() (File, error)
}
type StatFile interface {
File
Stat() os.FileInfo
}
type PeekFile interface {
SizeFile
Peek(n int) File
Length() int
}
type SizeFile interface {
File
Size() (int64, error)
}
type FileInfo interface {
FullPath() string
Stat() os.FileInfo
}