File Storage API

Akshell provides applications with a simple file storage. Files are served by a web server from http://static.akshell.com/media/ with a far future Expires header; anyone can access them for browsing and reading. An application manages its storage via the fs module functions described here.

Concepts

Akshell storage entries are files and directories organized into a traditional treelike structure; entry names can contain any Unicode symbols except '\0', '\n', and '/'. An application identify its storage entries by paths; name delimiting character is the slash ('/'). Application clients retrieve entries from URLs of the form http://static.akshell.com/media/prefix/path where prefix is release/appName for the release version of the application and spots/appName/ownerName/spotName for a spot one (ownerName has spaces replaced by hyphens).

For example, the file hello.txt in the subdirectory subdir of the directory dir has a path 'dir/subdir/hello.txt'. In the release version of the example application it has an URL http://static.akshell.com/media/release/example/dir/subdir/hello.txt, in Anton Korenyushkin’s (mine) spot debug it has an URL http://static.akshell.com/media/spots/example/Anton-Korenyushkin/debug/dir/subdir/hello.txt.

Functions

fs.open([appName], path)

Open a file and return a fs.File object.

fs.read([appName], path)

Return file contents represented by a Binary object.

fs.write(path, data)

Coerce data to Binary and write it into a file; if the file already exists, overwrite it.

fs.list([appName], path)

Return an array of names of directory subentries in arbitrary order.

fs.exists([appName], path)

Test whether an entry exists.

fs.isDir([appName], path)

Test whether an entry exists and is a directory.

fs.isFile([appName], path)

Test whether an entry exists and is a file.

fs.getModDate([appName], path)

Return a modification Date of an entry.

fs.createDir(path)

Create a directory; fail if the parent directory does not exist.

fs.remove(path)

Remove an entry; if it’s a directory, remove it recursively.

fs.rename(oldPath, newPath)

Change a path of an entry; fail if newPath already exists or its parent directory does not exist.

File

class fs.File

A File object provides means of reading and writing a file. It can be obtained via the fs.open() function or the files Request property. In the latter case file is read-only.

closed

true if the file is closed; false otherwise.

writable

true if the file is writable; false otherwise.

length

The length of the file, in bytes. If the file is writable, length is assignable.

position

The position within the file at which the next read or write operation occurs, in bytes. Setting position to a new value moves the stream’s position to the given byte offset.

read([max])

Read max bytes from the stream, or until the end of the file has been reached, and return a Binary object. If the argument is omitted, read until the end of the file.

write(data)

Coerce data to Binary and write it to the file. Return this.

flush()

Flush the file to the disc. Return this.

close()

Close the file, freeing the resources it is holding. close() can be called multiple times; all other operations on a closed file result in a ValueError exception.

Exceptions

exception FSError

A base class of all file storage exceptions.

exception PathError

Incorrect path.

exception EntryExistsError

Entry already exists

exception NoSuchEntryError

Entry doesn’t exist.

exception EntryIsDirError

Entry is a directory.

exception EntryIsNotDirError

Entry is not a directory.

exception FileIsReadOnly

Attempt to write into a read-only file.

exception FSQuotaError

File storage quota exceeded.