LCOV - code coverage report
Current view: top level - lib - getdents.js (source / functions) Hit Total Coverage
Test: lcov_final.info Lines: 99 99 100.0 %
Date: 2021-10-30 22:51:46 Functions: 6 6 100.0 %
Branches: 16 16 100.0 %

           Branch data     Line data    Source code
       1            [ + ]:          1 : const os = require('os'),
       2                 :          1 :       util = require('util'),
       3                 :          1 :       _Getdents = require('bindings')('getdents.node').Getdents;
       4                 :          1 : 
       5                 :          1 : let read16;
       6                 :          1 : if (os.endianness() === 'LE')
       7                 :          1 : {
       8            [ + ]:          1 :         read16 = function (buf, pos)
       9                 :         24 :         {
      10                 :         24 :                 return buf.readUInt16LE(pos);
      11                 :          1 :         };
      12                 :          1 : }
      13            [ + ]:          1 : /* c8 ignore start */
      14                 :          1 : else
      15                 :          1 : {
      16                 :          1 :         read16 = function (buf, pos)
      17                 :          1 :         {
      18                 :          1 :                 return buf.readUInt16BE(pos);
      19                 :          1 :         };
      20                 :          1 : }
      21                 :          1 : /* c8 ignore stop */
      22                 :          1 : 
      23                 :          1 : let zero_inode = Buffer.alloc(8);
      24                 :          1 : 
      25                 :          1 : /*
      26                 :          1 : struct linux_dirent64 {
      27                 :          1 :    ino64_t        d_ino;    // 64-bit inode number
      28                 :          1 :    off64_t        d_off;    // 64-bit offset to next structure
      29                 :          1 :    unsigned short d_reclen; // Size of this dirent
      30                 :          1 :    unsigned char  d_type;   // File type
      31                 :          1 :    char           d_name[]; // Filename (null-terminated)
      32                 :          1 : };
      33                 :          1 : */
      34                 :          1 : 
      35                 :          1 : class Getdents extends _Getdents
      36                 :          1 : {
      37            [ + ]:          1 :     constructor(size, fd)
      38                 :          2 :     {
      39                 :          2 :         super();
      40                 :          2 :         this._buf = Buffer.alloc(size);
      41                 :          2 :         this.reset(fd);
      42                 :          2 :         this._pnext = util.promisify(this.next);
      43                 :          2 :     }
      44                 :          1 : 
      45            [ + ]:          1 :     reset(fd)
      46                 :         14 :     {
      47       [ + ][ + ]:         14 :         this.fd = fd === undefined ? 0 : fd;
      48                 :         14 :         this._next = 0;
      49                 :         14 :     }
      50                 :          1 : 
      51            [ + ]:          1 :     *_process(n)
      52                 :         10 :     {
      53                 :         10 :         this._pos = 0;
      54                 :         10 :         while (this._pos < n)
      55            [ + ]:         10 :         {
      56                 :         24 :             /* istanbul ignore else */
      57                 :         24 :             if (!this._buf.slice(0, 8).equals(zero_inode)) // d_ino
      58                 :         24 :             {
      59                 :         24 :                 this._next = this._pos +
      60                 :         24 :                              read16(this._buf, this._pos + 16); // d_reclen
      61                 :         24 :                 yield;
      62                 :         24 :                 this._pos = this._next;
      63                 :         24 :             }
      64                 :         24 :         }
      65                 :         10 :     }
      66                 :          1 : 
      67            [ + ]:          1 :     *[Symbol.iterator]()
      68                 :          4 :     {
      69                 :          4 :         let n;
      70                 :          4 :         while ((n = super.nextSync(this._buf)) > 0)
      71            [ + ]:          4 :         {
      72                 :          5 :             yield* this._process(n);
      73                 :          5 :         }
      74                 :          4 :     }
      75                 :          1 : 
      76            [ + ]:          1 :     async *[Symbol.asyncIterator]()
      77                 :          4 :     {
      78                 :          4 :         let n;
      79            [ + ]:          4 :         while ((n = await this._pnext(this._buf)) > 0)
      80            [ + ]:          4 :         {
      81                 :          5 :             yield* this._process(n);
      82                 :          5 :         }
      83                 :          4 :     }
      84                 :          1 : 
      85            [ + ]:          1 :     get type()
      86                 :         24 :     {
      87                 :         24 :         return this._buf[this._pos + 18]; // d_type
      88                 :         24 :     }
      89                 :          1 : 
      90            [ + ]:          1 :     get name()
      91                 :         24 :     {
      92                 :         24 :         let name_start = this._pos + 19, // d_name
      93                 :         24 :             search_start = this._next - _Getdents.alignment,
      94                 :         24 :             name_end = this._buf.indexOf(0, Math.max(search_start, name_start));
      95                 :         24 :         return this._buf.toString('utf8', name_start, name_end);
      96                 :         24 :     }
      97                 :          1 : }
      98                 :          1 : 
      99                 :          1 : exports.Getdents = Getdents;

Generated by: LCOV version 1.14