file

package
v1.1.0-no-httpretry-fix Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2023 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

Package file provides a series of file creation functions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MediaType

func MediaType(i interface{}) string

MediaType returns the file's mime type. If the mime type cannot be determined, it returns "application/octet-stream".

The i should be a *os.File, io.Reader, or byte slice.

func NewMultiFileReader

func NewMultiFileReader(path string, form bool) (*files.MultiFileReader, error)

NewMultiFileReader constructs a files.MultiFileReader via github.com/ipfs/go-ipfs-files. `path` can be any `commands.Directory`. If `form` is set to true, the Content-Disposition will be "form-data". Otherwise, it will be "attachment".

It returns an io.Reader and error.

Types

type MultiFileReader

type MultiFileReader struct {
	io.Reader
	// contains filtered or unexported fields
}

MultiFileReader reads from a `commands.Node` (which can be a directory of files or a regular file) as HTTP multipart encoded data.

func CreateMultiForm

func CreateMultiForm(node *Node, form bool) (mfr *MultiFileReader, err error)

CreateMultiForm constructs a MultiFileReader. `path` should be a Node in serialfile. If `form` is set to true, the Content-Disposition will be "form-data". Otherwise, it will be "attachment".

It returns an io.Reader and error.

Example:

> node, err := file.NewSerialFile("directory-path") > > node.MapDirectory("a-dir-name-show-in-pinning-service")

func (*MultiFileReader) Boundary

func (mfr *MultiFileReader) Boundary() string

Boundary returns the boundary string to be used to separate files in the multipart data

func (*MultiFileReader) Write

func (mfr *MultiFileReader) Write(header textproto.MIMEHeader, content []byte) error

type Node

type Node struct {
	// contains filtered or unexported fields
}

Node represents a serial files.

func NewSerialFile

func NewSerialFile(root string) (node *Node, err error)

NewSerialFile adopts serial files and returns a Node represents a file, directory, or special file.

func (*Node) MapDirectory

func (n *Node) MapDirectory(name string)

MapDirectory sets up a new target directory by given path name.

func (*Node) Mode

func (n *Node) Mode() os.FileMode

Mode returns a os.FileMode of Node

func (*Node) Size

func (n *Node) Size() (du int64, err error)

Size returns the file size of the Node.

Jump to

Keyboard shortcuts

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