Skip to content

MediaBrowser

The MediaBrowser module lets you navigate directory structures.

First use the Drives module to get the MRL of a storage location. Then pass this MRL to the getContents function to get a list of File objects.

Methods

getContents(mrl, filter, template)

This function lists all files in a directory. Special files "." and ".." are also inluded. If the directory contains other directories, call this function recursively to get their contents.

Folders can contain a large number of files. You should use the filter argument to specify what subset of files to return. Right now the filter only supports skipping a number of initial files (offset), and limiting the number of returned files (limit). If you plan to use this feature, you will also want to know in advance the total number of files in the directory. Get it by calling getFileCount.

In the future we might add support for filtering by mime-type, etc.

Passing null for the filter will return all elements.

Parameters:

Name Type Description
mrl MRL The MRL of the folder whose contents we want.
filter Object A filter for the returned Array. Properties:
NameTypeDescription
offsetNumberAn offset from which to return files.
limitNumberThe maximum number of files to return.
template Template A template for the returned Array.

Returns:

Type Description
A promise. The completion handler will be passed the following arguments:
- files: An Array of File objects, populated as per the template.

getFileCount(mrl)

This function reports the number of files in a directory. You will want to use it in conjunction with the filter argument of getContents.

Name Type Description
mrl MRL The MRL of the folder whose contents we want.

Returns:

Type Description
A promise. The completion handler will be passed the following arguments:
- count: The number of Files in the directory.

Type Definitions

File

A description for a file.

Properties:

Name Type Description
mrl MRL The file's MRL.
name String The file's name.
size Number The file's size in bytes. Ignore this if the file is a directory.
dir Boolean Will be true if the file is a directory.
created Timestamp When the file was created.
accessed Timestamp When the file was last accessed.
modified Timestamp When the file was last modified.
Back to top