Mercurial > code > home > repos > streamed-graph
annotate src/fetchAndParse.ts @ 95:47d3b5a5bd5e
refactor
author | drewp@bigasterisk.com |
---|---|
date | Wed, 12 Jan 2022 22:15:13 -0800 |
parents | |
children | ab7dca42afbd |
rev | line source |
---|---|
95 | 1 import { Store, Parser } from "n3"; |
2 | |
3 export async function fetchAndParse(url: string): Promise<Store> { | |
4 const store = new Store(); | |
5 const res = await fetch(url); | |
6 const body = await res.text(); | |
7 const parser = new Parser({ format: "N3" }); | |
8 await new Promise((done, rej) => { | |
9 parser.parse(body, (err, quad, prefixes) => { | |
10 if (err) { | |
11 throw err; | |
12 } | |
13 if (quad) { | |
14 store.addQuad(quad); | |
15 } else { | |
16 done(null); | |
17 } | |
18 }); | |
19 }); | |
20 return store; | |
21 } |