Files Module

The files module can be used to serve from the file system. It encapsulates common patterns like verifying that back-symlinks or keywords aren't used to gain access outside the intended folder.

Functions and values

Function or value Description

browse rootPath

Full Usage: browse rootPath

Parameters:
    rootPath : string

Returns: WebPart

'browse' the file in the sense that the contents of the file are sent based on the request's Url property. Will serve from the passed root path/directory.

The current implementation doesn't take kindly to relative paths.

rootPath : string
Returns: WebPart

browseFile rootPath fileName

Full Usage: browseFile rootPath fileName

Parameters:
    rootPath : string
    fileName : string

Returns: WebPart

'browse' the file given as the filename, by sending it to the browser with a MIME-type/Content-Type header based on its extension. Will service from the rootPath.

rootPath : string
fileName : string
Returns: WebPart

browseFileHome fileName

Full Usage: browseFileHome fileName

Parameters:
    fileName : string

Returns: WebPart

'browse' the file given as the filename, by sending it to the browser with a MIME-type/Content-Type header based on its extension. Will service from the current directory.

fileName : string
Returns: WebPart

browseHome

Full Usage: browseHome

Returns: WebPart

'browse' the file in the sense that the contents of the file are sent based on the request's Url property. Will serve from the current as configured in directory. Suave's runtime.

Returns: WebPart

dir rootPath

Full Usage: dir rootPath

Parameters:
    rootPath : string

Returns: WebPart

Serve a 'file browser' for a rootPath

The current implementation doesn't take kindly to relative paths.

rootPath : string
Returns: WebPart

dirHome

Full Usage: dirHome

Returns: WebPart

Serve a 'file browser' for the current directory

Returns: WebPart

file fileName

Full Usage: file fileName

Parameters:
    fileName : string

Returns: WebPart

Send the embedded file by the filename given. Will search relative to the current assembly. Will also set the MIME type based on the file extension.

fileName : string
Returns: WebPart

fileEtag fileName

Full Usage: fileEtag fileName

Parameters:
    fileName : string

Returns: string

Compute a weak ETag for the file at the given path from its length and last-write time. This is cheap (no file hashing), stable across processes, and invalidates automatically when the file is modified. Used by file (and therefore by browse, browseHome, browseFile, browseFileHome) to populate the ETag response header and honour the If-None-Match request header.

fileName : string
Returns: string

resolvePath rootPath fileName

Full Usage: resolvePath rootPath fileName

Parameters:
    rootPath : string
    fileName : string

Returns: string

Format a string with a local file path given a file name 'fileName'. You should use this helper method to find the current directory and concatenate that current directory to the filename which should be absolute and start with a path separator.

The current implementation doesn't take kindly to relative paths.

rootPath : string
fileName : string
Returns: string

sendFile fileName compression

Full Usage: sendFile fileName compression

Parameters:
    fileName : string
    compression : bool

Returns: WebPart

Send a file as a response to the request

fileName : string
compression : bool
Returns: WebPart