Documentation ¶
Index ¶
- type ChecksumKind
- type File
- func (file *File) Bytes() ([]byte, error)
- func (file *File) Checksum(kind ChecksumKind) (string, error)
- func (file *File) Copy(dest string) error
- func (file *File) CopyWithHash(kind ChecksumKind, dest string) (*string, error)
- func (file *File) Delete() error
- func (file *File) DeleteRecursively() error
- func (file *File) IsDir() (bool, error)
- func (file *File) Json(t interface{}) error
- func (file *File) MkdirParent() error
- func (file *File) Move(dest string) error
- func (file *File) MoveTo(dir string) error
- func (file *File) Overwrite(t any) error
- func (file *File) OverwriteMarshal(marshal paopao.Marshaller, t any) error
- func (file *File) Path() string
- func (file *File) Reader() (*streaming.Reader, error)
- func (file *File) Recurse(nested bool, fn func(file *File)) error
- func (file *File) Rename(name string) error
- func (file *File) Text() (string, error)
- func (file *File) TextReader() (*streaming.TextReader, error)
- func (file *File) UncachedIsDir() (bool, error)
- func (file *File) Unmarshal(unmarshal paopao.Unmarshaler, t interface{}) error
- func (file *File) Write(t any) error
- func (file *File) WriteMarshal(marshal paopao.Marshaller, t any) error
- func (file *File) Writer(overwrite bool) (*streaming.Writer, error)
- func (file *File) WriterSize(overwrite bool, size int) (*streaming.Writer, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ChecksumKind ¶ added in v1.0.2
type ChecksumKind string
const ( Sha512Checksum ChecksumKind = "sha512" Sha256Checksum ChecksumKind = "sha256" Md5Checksum ChecksumKind = "md5" )
type File ¶
type File struct {
// contains filtered or unexported fields
}
func Open ¶
Open opens up a new interface with the given file.
siopao.Open will lazily open the file, which means that the file is opened as many times as it is needed and is closed immediately after use, unless it is needed by streaming. This prevents unnecessary resources from being leaked.
func (*File) Bytes ¶
Bytes reads the file directly as a byte array, this is not recommend to use when handling big files, we recommend using Reader to stream big files instead.
func (*File) Checksum ¶ added in v1.0.2
func (file *File) Checksum(kind ChecksumKind) (string, error)
Checksum gets the checksum hash of the file's contents.
func (*File) Copy ¶ added in v1.0.2
Copy copies the contents of the given source (file) into the destination.
func (*File) CopyWithHash ¶ added in v1.0.2
func (file *File) CopyWithHash(kind ChecksumKind, dest string) (*string, error)
CopyWithHash works similar to Copy but also creates a hash of the contents.
func (*File) Delete ¶ added in v1.0.2
Delete deletes the file, or an empty directory. If you need to delete a directory that isn't empty, then use DeleteRecursively instead.
func (*File) DeleteRecursively ¶ added in v1.0.2
DeleteRecursively deletes the file or directory and its children, if there are any, simply a short-hand of os.RemoveAll.
func (*File) IsDir ¶ added in v1.0.5
IsDir checks whether the file is a directory, when the File comes from a Recurse call, or another call previously used `IsDir` then that value will be cached. To not use the cached value, use the UncachedIsDir method instead.
func (*File) MkdirParent ¶ added in v1.0.6
MkdirParent creates the parent folders of the path, this also includes the current path if it is a directory already.
func (*File) Move ¶ added in v1.0.2
Move renames, or moves the file to another path. This is a more direct approach, and will be able to move the file to another folder. If you want to simply rename the file's name, use Rename instead, otherwise, if you want to keep the name, but move the folder, use MoveTo instead.
func (*File) MoveTo ¶ added in v1.0.2
MoveTo moves the file to another folder while keeping its name, this is useful when you just want to change the folder of the file.
If you want to move the file into an entirely new folder, use Move instead. You can also use Rename if you want to rename the file's name.
func (*File) Overwrite ¶
Overwrite overwrites the file and writes the content to the file. Anything other than string, io.Reader and []byte is marshaled into Json with the paopao.Marshal.
func (*File) OverwriteMarshal ¶
func (file *File) OverwriteMarshal(marshal paopao.Marshaller, t any) error
OverwriteMarshal works like Overwrite, but marshals anything other than string and []byte with the provided marshal.
func (*File) Reader ¶
Reader opens a stream to the file, allowing you to handle big file streaming easily.
This causes the file to be opened, therefore, we recommend using the returned streaming.Reader immediately to prevent unnecessary leaking of resources.
func (*File) Recurse ¶ added in v1.0.5
Recurse recurses through the directory if it's a directory. You can specify whether to recurse deep into the directory by setting the nested option to true.
func (*File) Rename ¶ added in v1.0.2
Rename renames the file while keeping the source folder, this is useful when you simply want to rename the name of the file, change the extension or something similar.
If you want to move the file into an entirely new folder, use Move instead. You can also use MoveTo if you want to move to another folder, but still keep the name.
func (*File) Text ¶
Text reads the file directly as a string, this is not recommended to use when handling big files, we recommend using TextReader to stream big files instead.
func (*File) TextReader ¶
func (file *File) TextReader() (*streaming.TextReader, error)
TextReader opens a string stream to the file, this is an abstraction over the streaming.Reader to handle text (string) instead of bytes.
This causes the file to be opened, therefore, we recommend using the returned streaming.Reader immediately to prevent unnecessary leaking of resources.
func (*File) UncachedIsDir ¶ added in v1.0.5
UncachedIsDir checks whether the file is a directory without passing through the cache. This is recommended to use when the file is frequently changing between a directory, or a file.
func (*File) Unmarshal ¶
func (file *File) Unmarshal(unmarshal paopao.Unmarshaler, t interface{}) error
Unmarshal unmarshals the given contents of the file with the given unmarshaler.
func (*File) Write ¶
Write writes, or appends if the file exists, the content to the file. Anything other than string, io.Reader and []byte is marshaled into Json with the paopao.Marshal.
func (*File) WriteMarshal ¶
func (file *File) WriteMarshal(marshal paopao.Marshaller, t any) error
WriteMarshal works like Write, but marshals anything other than string and []byte with the provided marshal.
func (*File) Writer ¶
Writer opens a write stream, allowing easier stream writing to the file. Unlike WriterSize, this opens a writing stream with a buffer size of 4,096 bytes, if you need to customize the buffer size, then use WriterSize instead.
This causes the file to be opened, it is up to you to close the streaming.Writer using the methods provided. We recommend using streaming.Writer's End method to close the writer as it flushes and closes the file.
func (*File) WriterSize ¶
WriterSize opens a write stream, allowing easier stream writing to the file. Unlike Writer, this opens a writing stream with the provided buffer size, although it's more recommended to use Writer unless you need to use a higher buffer size.
This causes the file to be opened, it is up to you to close the streaming.Writer using the methods provided. We recommend using streaming.Writer's End method to close the writer as it flushes and closes the file.