export const downloadFile = (url: string, outputDirectory: string) =>
Effect.gen(function* (_) {
const filename = new URL(url).pathname.slice(1);
const fs = yield* FileSystem.FileSystem;
const path = yield* Path.Path;
const filePath = path.join(outputDirectory, `${filename}.mp3`);
yield* fs.makeDirectory(outputDirectory, { recursive: true });
yield* Effect.log(`downloading file to ${filePath}`);
const response = yield* Http.request.get(url).pipe(Http.client.fetchOk);
yield* Effect.log(`response.statusCode: ${response.status}`);
yield* response.stream.pipe(Stream.run(fs.sink(filePath)));
yield* Effect.log("done streaming to file");
return yield* Effect.succeed(filePath);
});
export const downloadFile = (url: string, outputDirectory: string) =>
Effect.gen(function* (_) {
const filename = new URL(url).pathname.slice(1);
const fs = yield* FileSystem.FileSystem;
const path = yield* Path.Path;
const filePath = path.join(outputDirectory, `${filename}.mp3`);
yield* fs.makeDirectory(outputDirectory, { recursive: true });
yield* Effect.log(`downloading file to ${filePath}`);
const response = yield* Http.request.get(url).pipe(Http.client.fetchOk);
yield* Effect.log(`response.statusCode: ${response.status}`);
yield* response.stream.pipe(Stream.run(fs.sink(filePath)));
yield* Effect.log("done streaming to file");
return yield* Effect.succeed(filePath);
});