@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
Parameter | Type | Description |
---|---|---|
request | OpenFileRequest |
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();