nimbus

package module
v0.0.0-...-c97e69e Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2020 License: MIT Imports: 13 Imported by: 0

README

Nimbus

PkgGoDev

This is a simple fileserver, written in Go, which facilitates uploading and downloading of files. For examples of how this software works, check out the examples directory in the project root.

Implementation Details

There is an interface type NimbusHTTP which defines the HTTP interface of the file server. There is currently one implementation of this:

  • NimbusHTTPFormImpl is the implementation which attempts to download a file from the user and save it to the server, through a request with type multipart/form-data. The server returns a string representing the server name for the uploaded file. Using this name as a query parameter (with the key as a configurable value), the user can then download the uploaded files.

Documentation

Index

Constants

View Source
const (
	DefaultTransferBuffSize = 256
	Mb10                    = (10 << 20)
)

Variables

View Source
var (
	// Set of extension indicating that all extensions should be allowed.
	ExtAll = []string{"_all_"}
	// Set of image extensions which are most commonly used on the web.
	// From: developer.mozilla.org/en-US/docs/Web/Media/Formats/Image_types
	ExtImg = []string{
		".apng", ".avif", ".gif", ".jpg", ".jpeg", ".jfif",
		".pjpeg", ".pjp", ".png", ".svg", ".webp", ".bmp",
	}
	// Set of extensions only allowing compressed files
	ExtComp = []string{".zip", ".tar", ".tgz", ".gz", ".bz2"}
	// Set of extensions only allowing text files
	ExtTxt = []string{".txt"}
)

Extension sets

Functions

This section is empty.

Types

type NimbusHTTP

type NimbusHTTP interface {
	Upload(w http.ResponseWriter, r *http.Request)
	UploadMany(w http.ResponseWriter, r *http.Request)
	Download(w http.ResponseWriter, r *http.Request)
	DownloadMany(w http.ResponseWriter, r *http.Request)
	Delete(w http.ResponseWriter, r *http.Request)
	Cleanup()
}

NimbusHTTP defines the HTTP interface for the Nimbus file server.

func NewHTTPFormImpl

func NewHTTPFormImpl(dfk string, maxSize, buffSize int64, tmpDir string,
	exts []string, allowNoExt bool) (NimbusHTTP, error)

NNewHTTPFormImpl creates and returns the form implementation of NimbusHTTP. The `dfk` argument is the "default file key" which is a string indicating the name of the file field in requests to be received. `maxSize` specifies the maximum supported file size and `buffSize` indicates the copy buffer size. `tmpDir` is the directory in which the uploaded files will be stored as temporary files. `exts` is a slice containing the extensions which should be permitted. `allowNoExt` specifies whether files without extensions should be handled.

type NimbusHTTPFormImpl

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

NimbusHTTPFormImpl is a NimbusHTTP implementation which handles file uploads performed using HTML forms or the FormData web API.

func (*NimbusHTTPFormImpl) Cleanup

func (n *NimbusHTTPFormImpl) Cleanup()

func (*NimbusHTTPFormImpl) Delete

func (*NimbusHTTPFormImpl) Download

func (n *NimbusHTTPFormImpl) Download(w http.ResponseWriter, r *http.Request)

Download defines the endpoint which writes the first requested file from the request queries under the specified "default file key" to the user.

func (*NimbusHTTPFormImpl) DownloadMany

func (n *NimbusHTTPFormImpl) DownloadMany(w http.ResponseWriter, r *http.Request)

DownloadMany decodes a JSON body from the response with a string[] in the `filenames` field which specifies which files to archive and download. A zip archive is returned when all specified files exist and the archiving process does not encounter any errors. Otherwise, the encountered error is reported.

func (*NimbusHTTPFormImpl) Upload

Upload defines the endpoint which performs the download to the server. A single file is expected, with the form It is assumed that files will contain extensions and that the extension is the part of the filename from the last '.' to the end of the filename. This substring is required to be non-empty.

func (*NimbusHTTPFormImpl) UploadMany

func (n *NimbusHTTPFormImpl) UploadMany(w http.ResponseWriter, _ *http.Request)

type Zipper

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

func NewZipper

func NewZipper(buff io.Writer) *Zipper

func (*Zipper) AddFile

func (z *Zipper) AddFile(filename string) error

func (*Zipper) Close

func (z *Zipper) Close() error

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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