JSPM

  • Created
  • Published
  • Downloads 15
  • Score
    100M100P100Q54043F
  • License Apache-2.0

File system interface abstraction with implementations for GCP GCS, AWS S3, and Local filesystem

Package Exports

  • @wholebuzz/fs

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@wholebuzz/fs) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

@wholebuzz/fs

FileSystem with atomic primitives enabling multiple readers and writers.

  • LocalFileSystem employs content hashing to approximate GCS Object Versioning.
  • GoogleCloudFileSystem provides consistent parallel access paterns.
  • S3FileSystem provides basic file system primitives.

Example

import { AnyFileSystem, GoogleCloudFileSystem, LocalFileSystem, S3FileSystem } from '@wholebuzz/fs'

const fs = new AnyFileSystem([
  { urlPrefix: 'gs://', fs: new GoogleCloudFileSystem() },
  { urlPrefix: 's3://', fs: new S3FileSystem() },
  { urlPrefix: '', fs: new LocalFileSystem() },
])

const localStream = fs.openReadableStream('/etc/hosts')
const cloudStream = fs.openReadableStream('gs://bucket/file')
yarn build
node lib/cli.js ls .

API Reference

@wholebuzz/fs / Exports

@wholebuzz/fs

Table of contents

Modules

@wholebuzz/fs / Exports / fs / FileSystem

Class: FileSystem

fs.FileSystem

File system interface for atomic primitives enabling multiple readers and writers.

Hierarchy

Table of contents

Constructors

Methods

Constructors

constructor

+ new FileSystem(): FileSystem

Returns: FileSystem

Methods

appendToFile

Abstract appendToFile(urlText: string, writeCallback: (stream: WritableStreamTree) => Promise<boolean>, createCallback?: (stream: WritableStreamTree) => Promise<boolean>, createOptions?: CreateOptions, appendOptions?: AppendOptions): Promise<null | FileStatus>

Appends to the file, safely. Either writeCallback or createCallback is called. For simple appends, the same paramter can be supplied for both writeCallback and createCallback.

Parameters

Name Type Description
urlText string The URL of the file to append to.
writeCallback (stream: WritableStreamTree) => Promise<boolean> Stream callback for appending to the file.
createCallback? (stream: WritableStreamTree) => Promise<boolean> Stream callback for initializing the file, if necessary.
createOptions? CreateOptions Initial metadata for initializing the file, if necessary.
appendOptions? AppendOptions -

Returns: Promise<null | FileStatus>

Defined in: fs.ts:157


copyFile

Abstract copyFile(sourceUrlText: string, destUrlText: string): Promise<boolean>

Copies the file.

Parameters

Name Type Description
sourceUrlText string The URL of the source file to copy.
destUrlText string The destination URL to copy the file to.

Returns: Promise<boolean>

Defined in: fs.ts:132


createFile

Abstract createFile(urlText: string, createCallback?: (stream: WritableStreamTree) => Promise<boolean>, createOptions?: CreateOptions): Promise<boolean>

Creates file, failing if the file already exists.

Parameters

Name Type Description
urlText string The URL of the file to create.
createCallback? (stream: WritableStreamTree) => Promise<boolean> Stream callback for initializing the file.
createOptions? CreateOptions Initial metadata.

Returns: Promise<boolean>

Defined in: fs.ts:109


ensureDirectory

Abstract ensureDirectory(urlText: string, mask?: number): Promise<boolean>

Ensures the directory exists

Parameters

Name Type Description
urlText string The URL of the directory.
mask? number -

Returns: Promise<boolean>

Defined in: fs.ts:71


fileExists

Abstract fileExists(urlText: string): Promise<boolean>

Returns true if the file exists.

Parameters

Name Type Description
urlText string The URL of the file to check whether exists.

Returns: Promise<boolean>

Defined in: fs.ts:77


getFileStatus

Abstract getFileStatus(urlText: string, getVersion?: boolean): Promise<FileStatus>

Determines the file status. The file version is used to implement atomic mutations.

Parameters

Name Type Description
urlText string The URL of the file to retrieve the status for.
getVersion? boolean -

Returns: Promise<FileStatus>

Defined in: fs.ts:83


openReadableFile

Abstract openReadableFile(url: string, version?: string | number): Promise<ReadableStreamTree>

Opens a file for reading.

optional version Fails if version doesn't match for GCS URLs.

Parameters

Name Type Description
url string The URL of the file to read from.
version? string | number -

Returns: Promise<ReadableStreamTree>

Defined in: fs.ts:90


openWritableFile

Abstract openWritableFile(url: string, version?: string | number, options?: CreateOptions): Promise<WritableStreamTree>

Opens a file for writing.

optional version Fails if version doesn't match for GCS URLs.

Parameters

Name Type Description
url string The URL of the file to write to.
version? string | number -
options? CreateOptions -

Returns: Promise<WritableStreamTree>

Defined in: fs.ts:97


queueRemoveFile

Abstract queueRemoveFile(urlText: string): Promise<boolean>

Queues deletion, e.g. after DaysSinceCustomTime.

Parameters

Name Type Description
urlText string The URL of the file to remove.

Returns: Promise<boolean>

Defined in: fs.ts:125


readDirectory

Abstract readDirectory(urlText: string): Promise<string[]>

Returns the URLs of the files in a directory.

Parameters

Name Type Description
urlText string The URL of the directory to list files in.

Returns: Promise<string[]>

Defined in: fs.ts:65


removeFile

Abstract removeFile(urlText: string): Promise<boolean>

Deletes the file.

Parameters

Name Type Description
urlText string The URL of the file to remove.

Returns: Promise<boolean>

Defined in: fs.ts:119


replaceFile

Abstract replaceFile(urlText: string, writeCallback: (stream: WritableStreamTree) => Promise<boolean>, createOptions?: CreateOptions, version?: string | number): Promise<boolean>

Replaces the file, failing if the file version doesn't match.

Parameters

Name Type Description
urlText string The URL of the file to replace.
writeCallback (stream: WritableStreamTree) => Promise<boolean> Stream callback for replacing the file.
createOptions? CreateOptions Initial metadata for replaced file.
version? string | number The version of the file to replace.

Returns: Promise<boolean>

Defined in: fs.ts:141