siopao

package
v1.0.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 28, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

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

func Open(path string) *File

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

func (file *File) Bytes() ([]byte, error)

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

func (file *File) Copy(dest string) error

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

func (file *File) Delete() error

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

func (file *File) DeleteRecursively() error

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

func (file *File) IsDir() (bool, error)

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) Json

func (file *File) Json(t interface{}) error

Json unmarshals the contents of the file into Json using the paopao.Unmarshal.

func (*File) MkdirParent added in v1.0.6

func (file *File) MkdirParent() error

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

func (file *File) Move(dest string) error

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

func (file *File) MoveTo(dir string) error

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

func (file *File) Overwrite(t any) error

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) Path added in v1.0.5

func (file *File) Path() string

Path gets the path of the file.

func (*File) Reader

func (file *File) Reader() (*streaming.Reader, error)

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

func (file *File) Recurse(nested bool, fn func(file *File)) error

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

func (file *File) Rename(name string) error

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

func (file *File) Text() (string, error)

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

func (file *File) UncachedIsDir() (bool, error)

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

func (file *File) Write(t any) error

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

func (file *File) Writer(overwrite bool) (*streaming.Writer, error)

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

func (file *File) WriterSize(overwrite bool, size int) (*streaming.Writer, error)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL