Last active
January 24, 2024 08:59
-
-
Save wmakeev/71f62e5ef35f0c4714651fd6db50031d to your computer and use it in GitHub Desktop.
[highland.js ETL] #etl #highland #tools
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const Kbyte = 1024; | |
export const Mbyte = Kbyte * Kbyte; | |
export const Gbyte = Kbyte * Mbyte; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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