fsutil

package
v5.0.0-preview1 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2023 License: MIT Imports: 8 Imported by: 11

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Delete

func Delete(path string)

Delete the file at the given path.

To avoid panics, you should check if the file exists.

func FileExists

func FileExists(file string) bool

FileExists returns true if the file at the given path exists and is readable. Returns false if the given file is a directory.

func GetFileExtension

func GetFileExtension(file string) string

GetFileExtension returns the last part of a file name. If the file doesn't have an extension, returns an empty string.

func GetMIMEType

func GetMIMEType(file string) (contentType string, size int64, err error)

GetMIMEType get the mime type and size of the given file. This function calls `http.DetectContentType`. If the detected content type could not be determined or if it's a text file, `GetMIMEType` will attempt to detect the MIME type based on the file extension. The following extensions are supported:

  • `.jsonld`: "application/ld+json"
  • `.json`: "application/json"
  • `.js` / `.mjs`: "text/javascript"
  • `.css`: "text/css"

If a specific MIME type cannot be determined, returns "application/octet-stream" as a fallback.

func IsDirectory

func IsDirectory(path string) bool

IsDirectory returns true if the file at the given path exists, is a directory and is readable.

Types

type File

type File struct {
	Header   *multipart.FileHeader
	MIMEType string
}

File represents a file received from client.

func ParseMultipartFiles

func ParseMultipartFiles(headers []*multipart.FileHeader) ([]File, error)

ParseMultipartFiles parse a single file field in a request.

func (*File) Save

func (file *File) Save(path string, name string) (filename string, err error)

Save writes the given file on the disk. Appends a timestamp to the given file name to avoid duplicate file names. The file is not readable anymore once saved as its FileReader has already been closed.

Creates directories if needed.

Returns the actual file name.

Jump to

Keyboard shortcuts

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