getdents

Call getdents(2) from Javscript

Usage no npm install needed!

<script type="module">
  import getdents from 'https://cdn.skypack.dev/getdents';
</script>

README

This is a Node.js module for calling getdents64 on Linux from Javascript.

You might want to use this instead of fs.readdir if you have a directory containing many files.

API documentation is available here.

Example

List regular files in /tmp:

const fs = require('fs'),
      assert = require('assert'),
      Getdents = require('getdents').Getdents;

fs.open('/tmp', 'r', async function (err, fd)
{
    assert.ifError(err);

    let getdents = new Getdents(1024 * 1024, fd);

    for await (let _ of getdents)
    {
        if (getdents.type === Getdents.DT_REG)
        {
            console.log(getdents.name);
        }
    }
});

Install

npm install getdents

Licence

MIT

Test

grunt test

Coverage

grunt coverage

LCOV results are available here.

Coveralls page is here.