Skip to content

Commit c24290b

Browse files
authored
feat(storage): Allow strings to be written to files (#150)
2 parents c1cb94a + 13a77b3 commit c24290b

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/api/storage/v0/storage.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,15 @@ export class File {
195195
* await storage.bucket("my-bucket").file("my-item").write(buf);
196196
* ```
197197
*/
198-
public async write (body: Uint8Array): Promise<void> {
198+
public async write (body: Uint8Array | string): Promise<void> {
199199
const request = new StorageWriteRequest();
200200
request.setBucketName(this.bucket.name);
201201
request.setKey(this.name);
202-
request.setBody(body);
202+
if (typeof body === 'string' || body instanceof String) {
203+
request.setBody(new TextEncoder().encode(body as string))
204+
} else {
205+
request.setBody(body);
206+
}
203207

204208
return new Promise((resolve, reject) => {
205209
this.storage.StorageServiceClient.write(request, (error) => {

0 commit comments

Comments
 (0)