files

module:files

Description:
  • Local files

Source:

module:files

Description:
  • S3 files

Source:

module:files

Description:
  • Files storage, upload and retrieval, local fs or S3

Source:

Members

(static) args :Array.<ConfigOptions>

Source:
Default Value:
  • [
      {
        "name": "root",
        "type": "path",
        "descr": "Root directory where to keep files"
      },
      {
        "name": "max-age",
        "type": "int",
        "descr": "Max age for files in ms, -1 to disable"
      },
      {
        "name": "no-cache",
        "type": "bool",
        "descr": "Serve files as non cacheable"
      },
      {
        "name": "last-modified",
        "type": "bool",
        "descr": "Serve Last-Modified header to support conditional requests"
      },
      {
        "name": "etag",
        "type": "bool",
        "descr": "Produce weak ETag header for static files"
      }
    ]

(static) args :Array.<ConfigOptions>

Source:
Default Value:
  • [
      {
        "name": "bucket",
        "type": "path",
        "descr": "Default bucket where to keep files"
      }
    ]

Methods

(async, static) acopy(source, dest, options) → {Promise(object)}

Description:
Source:
Parameters:
Name Type Description
source string
dest string
options object
Returns:
Type Description
Promise(object)

in format { err, data }

(async, static) adel(file, options) → {Promise(object)}

Description:
Source:
Parameters:
Name Type Description
file string
options object
Returns:
Type Description
Promise(object)

in format { err, data }

(async, static) adetect(file, flagsopt) → {Promise(object)}

Description:
Source:
Parameters:
Name Type Attributes Description
file string | Buffer
flags string <optional>
Returns:
Type Description
Promise(object)

in format { err, data, ext }

(async, static) adetectAndStore(file, outfile, options) → {Promise(object)}

Description:
Source:
Parameters:
Name Type Description
file string | Buffer
outfile string
options object
Returns:
Type Description
Promise(object)

in format { err, data }

(async, static) alist(root, options) → {Promise(object)}

Description:
Source:
Parameters:
Name Type Description
root string

folder to show files

options object
Returns:
Type Description
Promise(object)

in format { err, data }

(async, static) aread(file, options) → {Promise(object)}

Description:
Source:
Parameters:
Name Type Description
file string
options object
Returns:
Type Description
Promise(object)

in format { err, data }

(async, static) astore(tmpfile, outfile, options) → {Promise(object)}

Description:
Source:
Parameters:
Name Type Description
tmpfile string | Buffer
outfile string
options object
Returns:
Type Description
Promise(object)

in format { err, data }

(async, static) aupload(req, name, options) → {Promise(object)}

Description:
Source:
Parameters:
Name Type Description
req Request
name string
options object
Returns:
Type Description
Promise(object)

in format { err, data }

(static) copy(source, dest, options, callback)

Description:
  • Copy a file from one location to another, can deal with local and S3 files if starts with s3:// prefix

Source:
Parameters:
Name Type Description
source string

source file, if not local this will be the files module

dest string

destination file, if it is not local but the source is local this will be files module

options object
callback function()

(static) del(file, options, callback)

Description:
  • Delete file by name from the local filesystem or S3 drive, no error is returned if the file does not exist to be compatible with S3 delete object

Source:
Parameters:
Name Type Description
file string
options object
callback function()

(static) del(oldname, newname, options, callback)

Description:
  • Rename a file in place, can deal with local and S3 files if starts with s3:// prefix

Source:
Parameters:
Name Type Description
oldname string
newname string
options object
callback function()

(static) detect(file, flagsopt, callbackopt)

Description:
  • Returns detected mime type and ext for a file, using the "file" utility, flags can be passed to the file utility to customize the output

Source:
Parameters:
Name Type Attributes Description
file string | Buffer

file or data

flags string <optional>

command line flags for the file utility (--mime-type)

callback function() <optional>

(err, mimeType, ext)

(static) detectAndStore(file, outfile, options, callback)

Description:
  • Detect file type and storee in one set

Source:
Parameters:
Name Type Description
file string | Buffer
outfile string
options object
callback function()

(static) getContentDisposition(filename) → {string}

Description:
  • Return Content-Disposition header for the given file name

Source:
Parameters:
Name Type Description
filename string
Returns:
Type Description
string

(static) getModule(path) → {object}

Description:
  • Return a module by path/url or type, the default module will be returns or files.file if no protocol or module exist

Source:
Parameters:
Name Type Description
path string

name, path or url, supports just protocol:

Returns:
Type Description
object

module by type

(static) list(root, optionsopt, callback)

Description:
  • Returns a list of file names inside the given path or S3 bucket

Source:
Parameters:
Name Type Attributes Description
root string

path prefix or root folder/bucket

options object <optional>
Properties
Name Type Attributes Description
exclude regexp <optional>

a regexp with file pattern to exclude, checks before the include buf after filter function

include regexp <optional>

can be a regexp to restrict which files to return

filter function() <optional>

a function(file, stat) that return 1 if the given file matches, stat is a object returned by fs.statSync

details boolean <optional>

return list of objects as { file, size, mtime }

base boolean <optional>

if set only keep base file name in the result, not full path

strip boolean <optional>

if set strip root prefix from full paths in details only

depth int <optional>

if a number it specifies max depth to go into the subfolders, starts with 0

callback function()

(static) read(file, optionsopt, callback)

Description:
  • Returns contents of a file, all specific parameters are passed as is, the contents of the file is returned to the callback, see module:lib.readFile or module.aws.s3GetFile for specific options.

Source:
Parameters:
Name Type Attributes Description
file string
options object <optional>
Properties
Name Type Attributes Description
cfg boolean <optional>

parse file in config format, name=value per line, return a list of args

json boolean <optional>

parse file as JSON, return an object, in case of error an empty object

list string <optional>

split contents with the given separator

callback function()

(static) send(context, file, optionsopt)

Description:
  • Send a file to the client

Source:
Parameters:
Name Type Attributes Description
context RequestContext

request

file string

file path

options object <optional>
Properties
Name Type Attributes Description
attachment boolean | string <optional>

download the file, only ASCII charcters

bucket string <optional>

S3 bucket

root string <optional>

root folder, takes precedence over s3

maxAge number <optional>

file cache age in ms

noCache boolean <optional>

return no-cache header

lastModified boolean <optional>

send Last-Modified header

etag boolean <optional>

generate and check weak etag

(static) store(tmpfile, outfile, optionsopt, callback)

Description:
  • Place a tmpfile to the destination pointed by outfile

Source:
Parameters:
Name Type Attributes Description
tmpfile string | Buffer | Stream
outfile string
options object <optional>
Properties
Name Type Attributes Description
copy boolean <optional>

use copy instead of move for local files

noreplace boolean <optional>

prevent overwriting existing files

extmap object <optional>

repkace file extentions according this map: { oldext: newext }

callback function()

(static) upload(context, name, options, callback)

Description:
  • Upload file and store in the filesystem or S3, try to find the file in multipart form or in the body by the given name On return the options may have the following properties set:

    • filesize - size of the file in bytes if available
    • filetype - file extention with dot
    • mimetype - file mime type if detected
Source:
Parameters:
Name Type Description
context RequestContext
name string

is the property to look for in the multipart body or in the request body

options object

Output file name is built according to the following options properties:

Properties
Name Type Attributes Description
name string <optional>

defines the output name for the file, if not given same name as property will be used

prefix string <optional>

the folder prefix where the file will be uploaded, all leading folders will be created automatically

ext string <optional>

what file extention to use, appended to the name, if no ext is given the extension from the uploaded file will be used or no extention if could not determine one.

extkeep boolean <optional>

keep actual extention from the uploaded file, ignore the ext parameter

extmap object <optional>

an object which extensions must be replaced

namekeep boolean <optional>

keep the name of the uploaded file if present in the multipart form

encoding string <optional>

encoding of the body, default is base64

allow regexp <optional>

a Regexp with allowed MIME types, this will use detect method to discover file type by the contents

maxsize int <optional>

refuse to save if the payload exceeds the given size

callback function()

will be called with err and actual filename saved

module:files

Description:
  • Local files

Source:

module:files

Description:
  • S3 files

Source:

module:files

Description:
  • Files storage, upload and retrieval, local fs or S3

Source:

Members

(static) args :Array.<ConfigOptions>

Source:
Default Value:
  • [
      {
        "name": "root",
        "type": "path",
        "descr": "Root directory where to keep files"
      },
      {
        "name": "max-age",
        "type": "int",
        "descr": "Max age for files in ms, -1 to disable"
      },
      {
        "name": "no-cache",
        "type": "bool",
        "descr": "Serve files as non cacheable"
      },
      {
        "name": "last-modified",
        "type": "bool",
        "descr": "Serve Last-Modified header to support conditional requests"
      },
      {
        "name": "etag",
        "type": "bool",
        "descr": "Produce weak ETag header for static files"
      }
    ]

(static) args :Array.<ConfigOptions>

Source:
Default Value:
  • [
      {
        "name": "bucket",
        "type": "path",
        "descr": "Default bucket where to keep files"
      }
    ]

Methods

(async, static) acopy(source, dest, options) → {Promise(object)}

Description:
Source:
Parameters:
Name Type Description
source string
dest string
options object
Returns:
Type Description
Promise(object)

in format { err, data }

(async, static) adel(file, options) → {Promise(object)}

Description:
Source:
Parameters:
Name Type Description
file string
options object
Returns:
Type Description
Promise(object)

in format { err, data }

(async, static) adetect(file, flagsopt) → {Promise(object)}

Description:
Source:
Parameters:
Name Type Attributes Description
file string | Buffer
flags string <optional>
Returns:
Type Description
Promise(object)

in format { err, data, ext }

(async, static) adetectAndStore(file, outfile, options) → {Promise(object)}

Description:
Source:
Parameters:
Name Type Description
file string | Buffer
outfile string
options object
Returns:
Type Description
Promise(object)

in format { err, data }

(async, static) alist(root, options) → {Promise(object)}

Description:
Source:
Parameters:
Name Type Description
root string

folder to show files

options object
Returns:
Type Description
Promise(object)

in format { err, data }

(async, static) aread(file, options) → {Promise(object)}

Description:
Source:
Parameters:
Name Type Description
file string
options object
Returns:
Type Description
Promise(object)

in format { err, data }

(async, static) astore(tmpfile, outfile, options) → {Promise(object)}

Description:
Source:
Parameters:
Name Type Description
tmpfile string | Buffer
outfile string
options object
Returns:
Type Description
Promise(object)

in format { err, data }

(async, static) aupload(req, name, options) → {Promise(object)}

Description:
Source:
Parameters:
Name Type Description
req Request
name string
options object
Returns:
Type Description
Promise(object)

in format { err, data }

(static) copy(source, dest, options, callback)

Description:
  • Copy a file from one location to another, can deal with local and S3 files if starts with s3:// prefix

Source:
Parameters:
Name Type Description
source string

source file, if not local this will be the files module

dest string

destination file, if it is not local but the source is local this will be files module

options object
callback function()

(static) del(file, options, callback)

Description:
  • Delete file by name from the local filesystem or S3 drive, no error is returned if the file does not exist to be compatible with S3 delete object

Source:
Parameters:
Name Type Description
file string
options object
callback function()

(static) del(oldname, newname, options, callback)

Description:
  • Rename a file in place, can deal with local and S3 files if starts with s3:// prefix

Source:
Parameters:
Name Type Description
oldname string
newname string
options object
callback function()

(static) detect(file, flagsopt, callbackopt)

Description:
  • Returns detected mime type and ext for a file, using the "file" utility, flags can be passed to the file utility to customize the output

Source:
Parameters:
Name Type Attributes Description
file string | Buffer

file or data

flags string <optional>

command line flags for the file utility (--mime-type)

callback function() <optional>

(err, mimeType, ext)

(static) detectAndStore(file, outfile, options, callback)

Description:
  • Detect file type and storee in one set

Source:
Parameters:
Name Type Description
file string | Buffer
outfile string
options object
callback function()

(static) getContentDisposition(filename) → {string}

Description:
  • Return Content-Disposition header for the given file name

Source:
Parameters:
Name Type Description
filename string
Returns:
Type Description
string

(static) getModule(path) → {object}

Description:
  • Return a module by path/url or type, the default module will be returns or files.file if no protocol or module exist

Source:
Parameters:
Name Type Description
path string

name, path or url, supports just protocol:

Returns:
Type Description
object

module by type

(static) list(root, optionsopt, callback)

Description:
  • Returns a list of file names inside the given path or S3 bucket

Source:
Parameters:
Name Type Attributes Description
root string

path prefix or root folder/bucket

options object <optional>
Properties
Name Type Attributes Description
exclude regexp <optional>

a regexp with file pattern to exclude, checks before the include buf after filter function

include regexp <optional>

can be a regexp to restrict which files to return

filter function() <optional>

a function(file, stat) that return 1 if the given file matches, stat is a object returned by fs.statSync

details boolean <optional>

return list of objects as { file, size, mtime }

base boolean <optional>

if set only keep base file name in the result, not full path

strip boolean <optional>

if set strip root prefix from full paths in details only

depth int <optional>

if a number it specifies max depth to go into the subfolders, starts with 0

callback function()

(static) read(file, optionsopt, callback)

Description:
  • Returns contents of a file, all specific parameters are passed as is, the contents of the file is returned to the callback, see module:lib.readFile or module.aws.s3GetFile for specific options.

Source:
Parameters:
Name Type Attributes Description
file string
options object <optional>
Properties
Name Type Attributes Description
cfg boolean <optional>

parse file in config format, name=value per line, return a list of args

json boolean <optional>

parse file as JSON, return an object, in case of error an empty object

list string <optional>

split contents with the given separator

callback function()

(static) send(context, file, optionsopt)

Description:
  • Send a file to the client

Source:
Parameters:
Name Type Attributes Description
context RequestContext

request

file string

file path

options object <optional>
Properties
Name Type Attributes Description
attachment boolean | string <optional>

download the file, only ASCII charcters

bucket string <optional>

S3 bucket

root string <optional>

root folder, takes precedence over s3

maxAge number <optional>

file cache age in ms

noCache boolean <optional>

return no-cache header

lastModified boolean <optional>

send Last-Modified header

etag boolean <optional>

generate and check weak etag

(static) store(tmpfile, outfile, optionsopt, callback)

Description:
  • Place a tmpfile to the destination pointed by outfile

Source:
Parameters:
Name Type Attributes Description
tmpfile string | Buffer | Stream
outfile string
options object <optional>
Properties
Name Type Attributes Description
copy boolean <optional>

use copy instead of move for local files

noreplace boolean <optional>

prevent overwriting existing files

extmap object <optional>

repkace file extentions according this map: { oldext: newext }

callback function()

(static) upload(context, name, options, callback)

Description:
  • Upload file and store in the filesystem or S3, try to find the file in multipart form or in the body by the given name On return the options may have the following properties set:

    • filesize - size of the file in bytes if available
    • filetype - file extention with dot
    • mimetype - file mime type if detected
Source:
Parameters:
Name Type Description
context RequestContext
name string

is the property to look for in the multipart body or in the request body

options object

Output file name is built according to the following options properties:

Properties
Name Type Attributes Description
name string <optional>

defines the output name for the file, if not given same name as property will be used

prefix string <optional>

the folder prefix where the file will be uploaded, all leading folders will be created automatically

ext string <optional>

what file extention to use, appended to the name, if no ext is given the extension from the uploaded file will be used or no extention if could not determine one.

extkeep boolean <optional>

keep actual extention from the uploaded file, ignore the ext parameter

extmap object <optional>

an object which extensions must be replaced

namekeep boolean <optional>

keep the name of the uploaded file if present in the multipart form

encoding string <optional>

encoding of the body, default is base64

allow regexp <optional>

a Regexp with allowed MIME types, this will use detect method to discover file type by the contents

maxsize int <optional>

refuse to save if the payload exceeds the given size

callback function()

will be called with err and actual filename saved

module:files

Description:
  • Local files

Source:

module:files

Description:
  • S3 files

Source:

module:files

Description:
  • Files storage, upload and retrieval, local fs or S3

Source:

Members

(static) args :Array.<ConfigOptions>

Source:
Default Value:
  • [
      {
        "name": "root",
        "type": "path",
        "descr": "Root directory where to keep files"
      },
      {
        "name": "max-age",
        "type": "int",
        "descr": "Max age for files in ms, -1 to disable"
      },
      {
        "name": "no-cache",
        "type": "bool",
        "descr": "Serve files as non cacheable"
      },
      {
        "name": "last-modified",
        "type": "bool",
        "descr": "Serve Last-Modified header to support conditional requests"
      },
      {
        "name": "etag",
        "type": "bool",
        "descr": "Produce weak ETag header for static files"
      }
    ]

(static) args :Array.<ConfigOptions>

Source:
Default Value:
  • [
      {
        "name": "bucket",
        "type": "path",
        "descr": "Default bucket where to keep files"
      }
    ]

Methods

(async, static) acopy(source, dest, options) → {Promise(object)}

Description:
Source:
Parameters:
Name Type Description
source string
dest string
options object
Returns:
Type Description
Promise(object)

in format { err, data }

(async, static) adel(file, options) → {Promise(object)}

Description:
Source:
Parameters:
Name Type Description
file string
options object
Returns:
Type Description
Promise(object)

in format { err, data }

(async, static) adetect(file, flagsopt) → {Promise(object)}

Description:
Source:
Parameters:
Name Type Attributes Description
file string | Buffer
flags string <optional>
Returns:
Type Description
Promise(object)

in format { err, data, ext }

(async, static) adetectAndStore(file, outfile, options) → {Promise(object)}

Description:
Source:
Parameters:
Name Type Description
file string | Buffer
outfile string
options object
Returns:
Type Description
Promise(object)

in format { err, data }

(async, static) alist(root, options) → {Promise(object)}

Description:
Source:
Parameters:
Name Type Description
root string

folder to show files

options object
Returns:
Type Description
Promise(object)

in format { err, data }

(async, static) aread(file, options) → {Promise(object)}

Description:
Source:
Parameters:
Name Type Description
file string
options object
Returns:
Type Description
Promise(object)

in format { err, data }

(async, static) astore(tmpfile, outfile, options) → {Promise(object)}

Description:
Source:
Parameters:
Name Type Description
tmpfile string | Buffer
outfile string
options object
Returns:
Type Description
Promise(object)

in format { err, data }

(async, static) aupload(req, name, options) → {Promise(object)}

Description:
Source:
Parameters:
Name Type Description
req Request
name string
options object
Returns:
Type Description
Promise(object)

in format { err, data }

(static) copy(source, dest, options, callback)

Description:
  • Copy a file from one location to another, can deal with local and S3 files if starts with s3:// prefix

Source:
Parameters:
Name Type Description
source string

source file, if not local this will be the files module

dest string

destination file, if it is not local but the source is local this will be files module

options object
callback function()

(static) del(file, options, callback)

Description:
  • Delete file by name from the local filesystem or S3 drive, no error is returned if the file does not exist to be compatible with S3 delete object

Source:
Parameters:
Name Type Description
file string
options object
callback function()

(static) del(oldname, newname, options, callback)

Description:
  • Rename a file in place, can deal with local and S3 files if starts with s3:// prefix

Source:
Parameters:
Name Type Description
oldname string
newname string
options object
callback function()

(static) detect(file, flagsopt, callbackopt)

Description:
  • Returns detected mime type and ext for a file, using the "file" utility, flags can be passed to the file utility to customize the output

Source:
Parameters:
Name Type Attributes Description
file string | Buffer

file or data

flags string <optional>

command line flags for the file utility (--mime-type)

callback function() <optional>

(err, mimeType, ext)

(static) detectAndStore(file, outfile, options, callback)

Description:
  • Detect file type and storee in one set

Source:
Parameters:
Name Type Description
file string | Buffer
outfile string
options object
callback function()

(static) getContentDisposition(filename) → {string}

Description:
  • Return Content-Disposition header for the given file name

Source:
Parameters:
Name Type Description
filename string
Returns:
Type Description
string

(static) getModule(path) → {object}

Description:
  • Return a module by path/url or type, the default module will be returns or files.file if no protocol or module exist

Source:
Parameters:
Name Type Description
path string

name, path or url, supports just protocol:

Returns:
Type Description
object

module by type

(static) list(root, optionsopt, callback)

Description:
  • Returns a list of file names inside the given path or S3 bucket

Source:
Parameters:
Name Type Attributes Description
root string

path prefix or root folder/bucket

options object <optional>
Properties
Name Type Attributes Description
exclude regexp <optional>

a regexp with file pattern to exclude, checks before the include buf after filter function

include regexp <optional>

can be a regexp to restrict which files to return

filter function() <optional>

a function(file, stat) that return 1 if the given file matches, stat is a object returned by fs.statSync

details boolean <optional>

return list of objects as { file, size, mtime }

base boolean <optional>

if set only keep base file name in the result, not full path

strip boolean <optional>

if set strip root prefix from full paths in details only

depth int <optional>

if a number it specifies max depth to go into the subfolders, starts with 0

callback function()

(static) read(file, optionsopt, callback)

Description:
  • Returns contents of a file, all specific parameters are passed as is, the contents of the file is returned to the callback, see module:lib.readFile or module.aws.s3GetFile for specific options.

Source:
Parameters:
Name Type Attributes Description
file string
options object <optional>
Properties
Name Type Attributes Description
cfg boolean <optional>

parse file in config format, name=value per line, return a list of args

json boolean <optional>

parse file as JSON, return an object, in case of error an empty object

list string <optional>

split contents with the given separator

callback function()

(static) send(context, file, optionsopt)

Description:
  • Send a file to the client

Source:
Parameters:
Name Type Attributes Description
context RequestContext

request

file string

file path

options object <optional>
Properties
Name Type Attributes Description
attachment boolean | string <optional>

download the file, only ASCII charcters

bucket string <optional>

S3 bucket

root string <optional>

root folder, takes precedence over s3

maxAge number <optional>

file cache age in ms

noCache boolean <optional>

return no-cache header

lastModified boolean <optional>

send Last-Modified header

etag boolean <optional>

generate and check weak etag

(static) store(tmpfile, outfile, optionsopt, callback)

Description:
  • Place a tmpfile to the destination pointed by outfile

Source:
Parameters:
Name Type Attributes Description
tmpfile string | Buffer | Stream
outfile string
options object <optional>
Properties
Name Type Attributes Description
copy boolean <optional>

use copy instead of move for local files

noreplace boolean <optional>

prevent overwriting existing files

extmap object <optional>

repkace file extentions according this map: { oldext: newext }

callback function()

(static) upload(context, name, options, callback)

Description:
  • Upload file and store in the filesystem or S3, try to find the file in multipart form or in the body by the given name On return the options may have the following properties set:

    • filesize - size of the file in bytes if available
    • filetype - file extention with dot
    • mimetype - file mime type if detected
Source:
Parameters:
Name Type Description
context RequestContext
name string

is the property to look for in the multipart body or in the request body

options object

Output file name is built according to the following options properties:

Properties
Name Type Attributes Description
name string <optional>

defines the output name for the file, if not given same name as property will be used

prefix string <optional>

the folder prefix where the file will be uploaded, all leading folders will be created automatically

ext string <optional>

what file extention to use, appended to the name, if no ext is given the extension from the uploaded file will be used or no extention if could not determine one.

extkeep boolean <optional>

keep actual extention from the uploaded file, ignore the ext parameter

extmap object <optional>

an object which extensions must be replaced

namekeep boolean <optional>

keep the name of the uploaded file if present in the multipart form

encoding string <optional>

encoding of the body, default is base64

allow regexp <optional>

a Regexp with allowed MIME types, this will use detect method to discover file type by the contents

maxsize int <optional>

refuse to save if the payload exceeds the given size

callback function()

will be called with err and actual filename saved