Space SDK Package

Space SDK Package

  • Users
  • Storage
  • Space Docs

›User Storage Methods

User Storage Methods

  • UserStorage.createFolder() method
  • UserStorage.listDirectory() method
  • UserStorage.addItems() method
  • UserStorage.openFile() method

Types

  • UserStorageConfig interface
  • CreateFolderRequest interface
  • ListDirectoryRequest interface
  • ListDirectoryResponse interface
  • AddItemsRequest interface
  • AddItemsResponse interface
  • AddItemsStatus interface
  • AddItemsResultSummary interface
  • OpenFileRequest interface
  • OpenFileResponse interface

@spacehq/sdk > UserStorage > openFile

UserStorage.openFile() method

openFile returns a stream (AsyncIterableIterator) of the file at the path in the bucket.

Signature:

openFile(request: OpenFileRequest): Promise<OpenFileResponse>;

Parameters

ParameterTypeDescription
requestOpenFileRequest

Returns:

Promise<OpenFileResponse>

Example

const spaceStorage = new UserStorage(spaceUser);

const response = await spaceStorage.openFile({ bucket: 'personal', path: '/file.txt' });
// response.stream is an async iterable
for await (const chunk of response.stream) {
   // aggregate the chunks based on your logic
}

// response also contains a convenience function consumeStream
const fileBytes = await response.consumeStream();

← UserStorage.addItems() methodUserStorageConfig interface →
  • UserStorage.openFile() method
  • Parameters
  • Example
Space SDK Package
Docs
Getting StartedUsersStorage
Resources
All DocumentationProject SlackBlog
More
GitHubStar
Follow @spacestorage