Created
October 14, 2018 21:26
-
-
Save 131/742b43cc71ddf3788125805c080ccb0a to your computer and use it in GitHub Desktop.
async iterator, are needed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
//this requires node 10 magical | |
const fs = require('fs'); | |
const path = require('path'); | |
const promisify = require('nyks/function/promisify'); | |
const readdir = async function * (dir) { | |
var entries = await promisify(fs.readdir)(dir); | |
for(let entry of entries) { | |
let filepath = path.join(dir, entry); | |
try { | |
let stat = fs.statSync(filepath); | |
if(stat.isDirectory()) { | |
for await(let subpath of readdir(filepath)) | |
yield subpath; | |
} else { | |
yield filepath; | |
} | |
} catch(err) {// stat failure | |
} | |
} | |
} | |
module.exports = readdir; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment