-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: bring file interface into package
I've elected to bring the file interface into this package itself to decouple from the ipfs codebase. I'm still thinking we'll track pretty closely with the IPFS definition of a file, but reduces the number of imports & provides greater islolation between the two codebases. This commit also brings a bunch of documentation fixes & updates in preparation for open sourcing.
- Loading branch information
Showing
8 changed files
with
117 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Contribute | ||
|
||
cafs is MIT licensed open source software. If you want to contribute, we're here to help you succeed. | ||
|
||
Please make sure to check out the [issues](https://github.com/qri-io/cafs/issues). Search the closed ones before reporting things, and (if you can!) help us with open ones. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// This file is pulled from github.com/ipfs/go-ipfs/commands/files | ||
// It's hoisted here to generalize for all cafs implementations. | ||
package cafs | ||
|
||
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 associated with this file | ||
FileName() string | ||
|
||
// FullPath returns the full path used when adding 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 { | ||
AbsPath() string | ||
Stat() os.FileInfo | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.