Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError [ERR_INVALID_ARG_TYPE]: The "fd" argument must be of type number. #3

Open
Groxot opened this issue Apr 16, 2020 · 1 comment

Comments

@Groxot
Copy link

Groxot commented Apr 16, 2020

I try to make eachRecord

  adt.open('./dev-scripts/adtImport/adtFiles/TypeSP.ADT', 'windows-1251', function(err, table) {
    const tableColumns = table.columns;
    table.eachRecord(function(err, record) {
      if(err){
        console.log(`err: ${JSON.stringify(err, null, 2)}`);
      }
      tableColumns.forEach(col => {
        console.log(col.name);
        console.log(record);
      });
      console.log(`next row`);
    });

    table.close(); // Optional
  });

First row logged successfuly.
But before start reading next row i have error:


internal/validators.js:113
    throw err;
    ^

TypeError [ERR_INVALID_ARG_TYPE]: The "fd" argument must be of type number. Received type object
    at Object.read (fs.js:456:3)
    at readNextRecord (\node_modules\node_adt\node_adt.js:150:10)
    at \node_modules\node_adt\node_adt.js:177:11
    at FSReqCallback.wrapper [as oncomplete] (fs.js:481:5)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @0.1.0 adt: `node dev-scripts/adtImport/index.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
@Groxot
Copy link
Author

Groxot commented Apr 17, 2020

Ok, i cover your functions and make some "hack" =)

const readAdtFilePromise = (...args) => {
  return new Promise((resolve, reject) => {
    adt.open(...args, (err, data) => {
      if (err) return reject(err);
      resolve(data)
    })
  })
};

const eachTableReq = (...args) => {
  return new Promise((resolve, reject) => {
    let obj = args.pop();
    obj.eachRecord(...args, (err, data) => {
      if (err) return reject(err);
      resolve(data)
    })
  })
};
const a = await readAdtFilePromise(fileName, 'windows-1251');
 const reqCount = a.header.recordCount;
 let data = [];
  for(let i = 0; i < reqCount; i++) {
    data.push(await eachTableReq({ limit: 1, offset: i }, a));
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant