(filePath: string, options: JsonInputOptionsNode = {})
| 34 | * ``` |
| 35 | */ |
| 36 | const $readJSON = async (filePath: string, options: JsonInputOptionsNode = {}) => { |
| 37 | const { method, headers, frameConfig } = { method: "GET", headers: {}, frameConfig: {}, ...options } |
| 38 | |
| 39 | if (filePath.startsWith("http") || filePath.startsWith("https")) { |
| 40 | |
| 41 | return new Promise((resolve, reject) => { |
| 42 | fetch(filePath, { method, headers }).then(response => { |
| 43 | if (response.status !== 200) { |
| 44 | throw new Error(`Failed to load ${filePath}`) |
| 45 | } |
| 46 | response.json().then(json => { |
| 47 | resolve(new DataFrame(json, frameConfig)); |
| 48 | }); |
| 49 | }).catch((err) => { |
| 50 | reject(err) |
| 51 | }) |
| 52 | }) |
| 53 | |
| 54 | } else { |
| 55 | return new Promise((resolve, reject) => { |
| 56 | fs.access(filePath, fs.constants.F_OK, (err) => { |
| 57 | if (err) { |
| 58 | reject("ENOENT: no such file or directory"); |
| 59 | } |
| 60 | const file = fs.readFileSync(filePath, "utf8") |
| 61 | const df = new DataFrame(JSON.parse(file), frameConfig); |
| 62 | resolve(df); |
| 63 | }) |
| 64 | }); |
| 65 | } |
| 66 | }; |
| 67 | |
| 68 | /** |
| 69 | * Streams a JSON file from local or remote location in chunks. Intermediate chunks is passed as a DataFrame to the callback function. |
nothing calls this directly
no test coverage detected