API Docs for: 0.8.0
Show:

FsMediaProvider Class

A media provider that uses the underlying file system as the method of storage.

Constructor

FsMediaProvider

(
  • context
)

Parameters:

  • context Object
    • [parentDir] String optional
    • site String

Methods

createWriteStream

(
  • mediaPath
  • cb
)

Creates a writable stream to a file with the specified path. The resource is overwritten if already exists.

Parameters:

  • mediaPath String

    The path/key to the media. Typically this is a path such as: /media/2014/9/540a3ff0e30ddfb9e60000be-1409957872680.jpg

  • cb Function

    A callback that provides two parameters: An Error, if occurred and a WriteableStream.

delete

(
  • mediaPath
  • cb
)

Deletes a file from the file system

Parameters:

  • mediaPath String

    The path/key to the media. Typically this is a path such as: /media/2014/9/540a3ff0e30ddfb9e60000be-1409957872680.jpg

  • cb Function

    A callback that provides two parameters: An Error, if occurred and the success of the operation.

exists

(
  • mediaPath
  • cb
)

Checks to see if the file actually exists on disk

Parameters:

  • mediaPath String

    The path/key to the media. Typically this is a path such as: /media/2014/9/540a3ff0e30ddfb9e60000be-1409957872680.jpg

  • cb Function

    A callback that provides two parameters: An Error, if occurred and a Boolean.

get

(
  • mediaPath
  • cb
)

Retrieves the content from the file system as a String or Buffer.

Parameters:

  • mediaPath String

    The path/key to the media. Typically this is a path such as: /media/2014/9/540a3ff0e30ddfb9e60000be-1409957872680.jpg

  • cb Function

    A callback that provides two parameters: An Error, if occurred and an entity that contains the media content.

getMediaPath

(
  • parentDir
  • mediaPath
)
String static

Generates an absolute path based on the parent directory and media path. The parent directory is expected to a single directory or set of directories nested under the pb.config.docRoot.

Parameters:

  • parentDir String
  • mediaPath String

Returns:

String:

Absolute path to the resource

getStream

(
  • mediaPath
  • [options]
  • cb
)

Retrieves the item on the file system as a stream.

Parameters:

  • mediaPath String

    The path/key to the media. Typically this is a path such as: /media/2014/9/540a3ff0e30ddfb9e60000be-1409957872680.jpg

  • [options] Object optional

    Options for interacting with S3

    • [bucket] String optional

      The S3 bucket to interact with

  • cb Function

    A callback that provides two parameters: An Error, if occurred and a ReadableStream that contains the media content.

mkdirs

(
  • absoluteFilePath
  • A
)

Recursively creates the directory structure based on the absolute file path provided.

Parameters:

  • absoluteFilePath String
  • A Function

    callback that provides two parameters: Error, if occurred and result of the attempt at the creation of each directory in the path.

setStream

(
  • stream
  • mediaPath
  • cb
)

Sets media content into the file system based on the specified media path and options. The stream provided must be a ReadableStream.

Parameters:

  • stream ReadableStream

    The content stream

  • mediaPath String

    The path/key to the media. Typically this is a path such as: /media/2014/9/540a3ff0e30ddfb9e60000be-1409957872680.jpg

  • cb Function

    A callback that provides two parameters: An Error, if occurred and the success of the operation.

setStream

(
  • fileDataStrOrBuffOrStream
  • mediaPath
  • cb
)

Sets media content into an file system based on the specified media path and options. The data must be in the form of a String or Buffer.

Parameters:

  • fileDataStrOrBuffOrStream String | Buffer

    The content to persist

  • mediaPath String

    The path/key to the media. Typically this is a path such as: /media/2014/9/540a3ff0e30ddfb9e60000be-1409957872680.jpg

  • cb Function

    A callback that provides two parameters: An Error, if occurred and the success of the operation.

stat

(
  • mediaPath
  • cb
)

Retrieve the stats on the file

Parameters:

  • mediaPath String

    The path/key to the media. Typically this is a path such as: /media/2014/9/540a3ff0e30ddfb9e60000be-1409957872680.jpg

  • cb Function

    A callback that provides two parameters: An Error, if occurred and an object that contains the file stats