Skip to content

Instantly share code, notes, and snippets.

@wmakeev
Last active January 24, 2024 08:59
Show Gist options
  • Save wmakeev/71f62e5ef35f0c4714651fd6db50031d to your computer and use it in GitHub Desktop.
Save wmakeev/71f62e5ef35f0c4714651fd6db50031d to your computer and use it in GitHub Desktop.
[highland.js ETL] #etl #highland #tools
export const Kbyte = 1024;
export const Mbyte = Kbyte * Kbyte;
export const Gbyte = Kbyte * Mbyte;
import { fetch } from "undici";
import _H from "highland";
import { promiseToStream } from "@wmakeev/highland-tools";
import { Readable } from "node:stream";
export function fromUrl(url: string) {
return _H([url])
.map(async (url) => {
const resp = await fetch(url);
if (resp.body == null) {
throw new Error("Empty response body");
}
return Readable.fromWeb(resp.body);
})
.map(promiseToStream)
.sequence()
.flatMap((body) => {
return _H(body);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment