import*as fs from'fs';import {streamArray}from'stream-json/streamers/StreamArray';import {ignore}from'stream-json/filters/Ignore';import Chain from'stream-chain';import pick from'stream-json/filters/Pick';/**
 * read json file content and parse it into array
 * use this method for large files instead of JSON.parse is more efficient
 * @param filePath the file location
 * @param listener callback to execute it while read and parse the json objects
 * @param path json array path in the file
 */
const readDataFromFile = (filePath, listener, path, ignorePath, transforms) => new Promise((resolve, reject) => {
  try {
    const fileStream = fs.createReadStream(filePath);
    // chain of file stream reader, json array locator, json array parser
    const streamChain = [fileStream];
    if (path) {
      streamChain.push(pick.withParser({
        filter: path
      }));
    }
    if (ignorePath) {
      streamChain.push(ignore({
        filter: ignorePath
      }));
    }
    streamChain.push(streamArray());
    streamChain.push(...transforms);
    const pipeline = Chain.chain(streamChain);
    pipeline.on('data', listener);
    pipeline.on('end', () => resolve(true));
  } catch (error) {
    reject(error);
  }
});
const sortBy = (list, key) => list.sort((a, b) => a[key] <= b[key] ? -1 : 1);export{readDataFromFile,sortBy};//# sourceMappingURL=stream-file.util.js.map
