Skip to content

Commit

Permalink
fix: writeRemoteURL
Browse files Browse the repository at this point in the history
  • Loading branch information
izatop committed Mar 16, 2023
1 parent b675241 commit 9a1561e
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions packages/fs/src/Bucket/FsBucket.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import http from "node:http";
import https from "node:https";
import {Readable} from "node:stream";
import {FileStorage} from "../FileStorage";
import {FsDriverAbstract} from "../Driver/FsDriverAbstract";
import {FsWritableFile, IBucketOptions} from "../interfaces";
Expand Down Expand Up @@ -41,6 +44,17 @@ export class FsBucket {
return this.#driver.write(this.name, path, file, metadata);
}

public async writeRemoteURL(path: string, url: string, metadata: Record<any, any>): Promise<string> {
const get = url.startsWith("https") ? https.get : http.get;
const stream = await new Promise<Readable>((resolve, reject) => (
get(url, (res) => resolve(res))
.on("error", reject)
.end()
));

return this.write(path, stream, metadata);
}

public async save(): Promise<void> {
await this.#driver.createBucket(this.name, this.region, true);
}
Expand Down

0 comments on commit 9a1561e

Please sign in to comment.