(where, opts, cb)
| 864 | ); |
| 865 | } |
| 866 | readdir(where, opts, cb) { |
| 867 | if (this.server) |
| 868 | throw new Error('Client-only method called in server mode'); |
| 869 | |
| 870 | if (typeof opts === 'function') { |
| 871 | cb = opts; |
| 872 | opts = {}; |
| 873 | } |
| 874 | if (typeof opts !== 'object' || opts === null) |
| 875 | opts = {}; |
| 876 | |
| 877 | const doFilter = (opts && opts.full ? false : true); |
| 878 | |
| 879 | if (!Buffer.isBuffer(where) && typeof where !== 'string') |
| 880 | throw new Error('missing directory handle or path'); |
| 881 | |
| 882 | if (typeof where === 'string') { |
| 883 | const entries = []; |
| 884 | let e = 0; |
| 885 | |
| 886 | const reread = (err, handle) => { |
| 887 | if (err) |
| 888 | return cb(err); |
| 889 | |
| 890 | this.readdir(handle, opts, (err, list) => { |
| 891 | const eof = (err && err.code === STATUS_CODE.EOF); |
| 892 | |
| 893 | if (err && !eof) |
| 894 | return this.close(handle, () => cb(err)); |
| 895 | |
| 896 | if (eof) { |
| 897 | return this.close(handle, (err) => { |
| 898 | if (err) |
| 899 | return cb(err); |
| 900 | cb(undefined, entries); |
| 901 | }); |
| 902 | } |
| 903 | |
| 904 | for (let i = 0; i < list.length; ++i, ++e) |
| 905 | entries[e] = list[i]; |
| 906 | |
| 907 | reread(undefined, handle); |
| 908 | }); |
| 909 | }; |
| 910 | return this.opendir(where, reread); |
| 911 | } |
| 912 | |
| 913 | /* |
| 914 | uint32 id |
| 915 | string handle |
| 916 | */ |
| 917 | const handleLen = where.length; |
| 918 | let p = 9; |
| 919 | const buf = Buffer.allocUnsafe(4 + 1 + 4 + 4 + handleLen); |
| 920 | |
| 921 | writeUInt32BE(buf, buf.length - 4, 0); |
| 922 | buf[4] = REQUEST.READDIR; |
| 923 | const reqid = this._writeReqid = (this._writeReqid + 1) & MAX_REQID; |
no test coverage detected