export class MyService extends Effect.Service<MyService>()("package/MyService", {
effect: Effect.gen(function* () {
const httpClient = yield* HttpClient.HttpClient.pipe(Effect.map(HttpClient.filterStatusOk));
const path = yield* Path.Path;
const fs = yield* FileSystem.FileSystem;
const downloadImage = (url: string) =>
Effect.gen(function* () {
const response = yield* httpClient.get(url, {});
const arrayBuffer = yield* response.arrayBuffer;
const buffer = new Uint8Array(arrayBuffer);
const fileName = path.basename(new URL(url).pathname);
const filePath = path.join("./downloads", fileName);
yield* fs.writeFile(filePath, buffer);
});
return { downloadImage } as const;
}),
dependencies: [NodeHttpClient.layerUndici, NodeContext.layer],
}) {}
export class MyService extends Effect.Service<MyService>()("package/MyService", {
effect: Effect.gen(function* () {
const httpClient = yield* HttpClient.HttpClient.pipe(Effect.map(HttpClient.filterStatusOk));
const path = yield* Path.Path;
const fs = yield* FileSystem.FileSystem;
const downloadImage = (url: string) =>
Effect.gen(function* () {
const response = yield* httpClient.get(url, {});
const arrayBuffer = yield* response.arrayBuffer;
const buffer = new Uint8Array(arrayBuffer);
const fileName = path.basename(new URL(url).pathname);
const filePath = path.join("./downloads", fileName);
yield* fs.writeFile(filePath, buffer);
});
return { downloadImage } as const;
}),
dependencies: [NodeHttpClient.layerUndici, NodeContext.layer],
}) {}