HPCloud-JS

API Docs for: 1.0.0
Show:

Container Class

Create a new container.

When a new container is created, no check is done against the server to ensure that the container exists. Thus, it is possible to have a local container object that does not point to a legitimate server-side container.

Constructor

Container

(
  • name
  • token
  • url
)

Parameters:

  • name String

    The name of the container.

  • token String

    An authentication token.

  • url String

    The URL of the container.

Methods

acl

(
  • fn
)
async

Get the ACL for the current container.

In some cases, this will result in a request to the remote server.

Parameters:

  • fn Function

    The callback, which will receive fn(Error e, ACL acl);

bytes

() Number

Get the byte count for this container.

Retrieves the number of bytes this container currently consumes.

Returns:

Number: The byte count (an Integer).

copy

(
  • info
  • newName
  • [containerName]
  • fn
)
async

Copy a resource from one path to another, or from one container to another.

This does a remote-side copy, so the payload is never transferred locally.

An interesting side effect of copy() is that you can change the metadata of a destination object by supplying alternative metadata during copy. You can also change content type and other properties. Since you can copy an object to itself, this is the cheapest way to change metadata.

To do this, provide an ObjectInfo as the first argument. That will then be used to set headers and metadata.

Parameters:

  • info ObjectInfo | String

    The object to copy.

  • newName String

    The name of the new object.

  • [containerName] String optional

    (Optional) The name of the container to copy to. If none is specified, the present container is used.

  • fn Function

    The callback, called like this: fn(Error e);

count

() Number

Get the number of objects in the container.

This returns the count of objects currently inside of the container. This is the total number of objects, not the number of objects at the "top level" of the container.

Returns:

Number: The number of items in the container.

decodeMetadata

(
  • headers
)
Object private

Decode the http headers meta data into a seperate object containing just the metadata.

Parameters:

  • headers Object

    http headers from a response.

Returns:

Object: An object with the metadata.

delete

(
  • name
  • fn
)
async

Delete an object.

Parameters:

  • name String

    The name of the object to delete.

  • fn Function

    The callback. Called with fn(Error e, boolean status). Errors are returned if the resource could not be found. status will be true if the resource was deleted.

encodeMetadata

(
  • metadata
  • [headers]
)
Object private

Convert the metadata to headers.

Parameters:

  • metadata Object

    An object with key value pairs of metadata.

  • [headers] Object optional

    An object with http headers (optional).

Returns:

Object: A headers object with metadata encoded and attached.

fetchDetails

(
  • contriner
  • fn
)
private async

fn(Error, Container);

Parameters:

  • contriner String
  • fn Function

metadata

(
  • fn
)
async

Get the metadata for a container.

Depending on how the container was constructed, this may require a trip to the remote server to fetch metadata.

Parameters:

  • fn Function

    The callback, which will receive two parameters: fn(Error e, Object metadata).

name

() String

Get the name of this container.

Returns:

String: The container name.

newFromJSON

(
  • json
  • token
  • url
)
Container static

Create a new Container from JSON data.

This is used to create a new container object from a JSON response.

Parameters:

  • json Object

    JSON data in the correct format.

  • token String

    The auth token.

  • url String

    The URL to object storage. This will be modified internally to point to this container.

Returns:

Container: A container object.

newFromResponse

(
  • name
  • response
  • token
  • endpoint
)
Container static

Construct a new Container from a response.

Internally, this is used to build a new container from HTTP headers.

Parameters:

  • name String

    The name of the container.

  • response HTTPResponse

    An HTTP response object.

  • token String

    An authentication token.

  • endpoint String

    The URL to the Swift REST endpoint. This is used as the base URL to construct a URL to the container itself.

Returns:

Container: A container object.

objectInfo

(
  • name
  • fn
)
async

Get information about an object.

This includes all of the standard data (name, content type, content length, eTag/md5, and so on) as well as any metadata that was attaached to the object.

This does NOT get the object's body. The object() method must be used for that.

Parameters:

  • name String

    The name of the object to retrieve.

  • fn Function

    A callback.

objectQuery

(
  • params
  • fn
)
async

Query for an object.

See objects(), objectsWithPrefix(), and objectsByPath() for simpler queries.

The following params are supported: - params.limit: set the maximum number of items returned - params.marker: get the next item after the named marker. Marker is an object name. - params.prefix: Use prefix/delimiter notation to get a "subdirectory" listing. - params.delimiter: the delimiter to use to separate directories. Usually '/'. - params.path: Use a path prefix to get children on a path.

Parameters:

  • params Object

    Any number of paramters, as specified above.

  • fn Function

    The callback, executed as fn(Error e, Array list). The Array is a list of ObjectInfo items and (depending on params) Subdir items.

objects

(
  • limit
  • [marker]
  • fn
)
async

Query for all the objects based on a limited set of criteria.

This is a wrapper around objectQuery.

Parameters:

  • limit Number

    The number of objects to limit the query to.

  • [marker] String optional

    Get the next item after the marker. A marker is an object name.

  • fn Function

    The callback, executed as fn(Error e, Array list). The Array is a list of ObjectInfo items and (depending on params) Subdir items.

objectsByPath

(
  • path
  • delimiter
  • [limit]
  • [marker]
  • fn
)
async

Specify a path (subdirectory) to traverse.

OpenStack Swift provides two basic ways to handle directory-like structures. The first is using a prefix (see objectsWithPrefix()). The second is to create directory markers and use a path.

A directory marker is just a file with a name that is directory-like. You create it exactly as you create any other file. Typically, it is 0 bytes long with the content type application/directory

Using objectsByPath() with directory markers will return a list of Object instances, some of which are regular files, and some of which are just empty directory marker files. When creating directory markers, you may wish to set metadata or content-type information indicating that they are directory markers.

At one point, the OpenStack documentation suggested that the path method was legacy. More recent versions of the documentation no longer indicate this.

Parameters:

  • path String

    The path to query objects for.

  • delimiter String

    A delimiter used to seperate paths in a directory like structure.

  • [limit] Number optional

    The number of objects to limit the query to.

  • [marker] String optional

    Get the next item after the marker. A marker is an object name.

  • fn Function

    The callback will receive fn(Error e, Array list), where the array is a list of ObjectInfo objects.

objectsWithPrefix

(
  • prefix
  • delimiter
  • limit
  • marker
  • fn
)
async

Retrieve a list of Objects with the given prefix.

Object Storage containers support directory-like organization. To get a list of items inside of a particular "subdirectory", provide the directory name as a "prefix". This will return only objects that begin with that prefix.

(Directory-like behavior is also supported by using "directory markers". See objectsByPath().)

Prefixes

Prefixes are basically substring patterns that are matched against files on the remote object storage.

When a prefix is used, object storage will begin to return not just Object instsances, but also Subdir instances. A Subdir is simply a container for a "path name".

Delimiters

Object Storage (OpenStack Swift) does not have a native concept of files and directories when it comes to paths. Instead, it merely represents them and simulates their behavior under specific circumstances.

The default behavior (when prefixes are used) is to treat the '/' character as a delimiter. Thus, when it encounters a name like this: foo/bar/baz.txt and the prefix is foo/, it will parse return a Subdir called foo/bar.

Setting delimiter will tell the Object Storage server which character to parse the filenames on. This means that if you use delimiters other than '/', you need to be very consistent with your usage or else you may get surprising results.

Parameters:

  • prefix String
  • delimiter String
  • limit Int
  • marker String
  • fn Function

    The callback will receive fn(Error e, Array list), where the array is a list of ObjectInfo objects.

remoteObject

(
  • name
  • fn
)
async

Get a RemoteObject instance.

This fetches an object from object storage.

The returned object is a stream, and will also have an ObjectInfo attached.

Importantly, no processing is done on the returned object. It is passed on as-is. No length or etag checking is done. No content type validation is done. The data is not read first and buffered.

Parameters:

  • name String

    The name of the object to fetch.

  • fn Function

    The callback, called as fn(Error e, RemoteObject o)

save

(
  • obj
  • content
  • fn
)
async

Write an object to the remote data store.

Importantly, certain fields on the ObjectInfo are ignored when saving: - eTag: This is generated on the fly to ensure accuracy. - Content-Length: This is not used, since we send with chunked encoding.

Parameters:

  • obj ObjectInfo

    The object to write.

  • content String | Buffer | Stream
  • fn Function

    The callback. fn(Error e, HTTPResponse r)

setMetadata

(
  • metadata
)

Set the metadata on the present object.

This does NOT save the metadata on the remote server.

Parameters:

  • metadata Object

    Name/value pairs for metadata. It is recommended that you encode the values prior to putting them here, as the Swift REST docs make no assumptions about how the metadata is encoded or decoded.

token

() String

Get the token used with this container.

Returns:

String: The token.

updateObjectMetadata

(
  • info
  • fn
)
async

Update the metadata on an object.

This allows you to update an object's metadata without requiring you to re-post the object's data payload.

According to the Swift documentation, this ONLY modifies the arbitrary metadata (See ObjectInfo.setMetadata()). Other info, including content type, disposition, and so on, cannot be changed this way.

IMPORTANT: To change the Content-Type of an object, you can use the Container.copy() method, copying the source to the same destination.

Parameters:

  • info ObjectInfo

    The local copy of the object that should be updated on the remote server.

  • fn Function

    The callback. This is called as fn(Error e).

url

() String

Get the URL of this container.

Returns:

String: The URL pointing to this container.