node-jsondir icon indicating copy to clipboard operation
node-jsondir copied to clipboard

Async all the things

Open feltnerm opened this issue 11 years ago • 2 comments

According to README:

All file operations are asynchronous. Love your callbacks.

I count 4 occurrences of synchronous operations in File.js. I understand it makes the code easier to understand and more maintainable, but I believe it'd add more extensibility to this library. I may add a patch, if you don't get to it before I do.

feltnerm avatar Nov 12 '13 02:11 feltnerm

It gets hairy when you're trying to instantiate a File object and I/O is happening in the constructor. Maybe I'm doing things wrong.

imhoffd avatar Nov 12 '13 06:11 imhoffd

Hmm.. I was thinking each File would be a readable Stream. It might require some control flow helper to not be a mess.

Making the recursive directory scanner an Event Emitter would be cool too. It would emit a 'file' or 'directory' event based on what it found. This would also open the up the door for others to maybe do some processing on each file or directory at some intermediary step before the final JSON structure is finished.

One question mark is how well does the OS handle multiple async file access operations? I know there's a limit to the number of files you can access at once (not sure if that limit is set in the OS or Node).

Not sure how practical, but the nerd in me would love love to be able to make this pipe-able too (especially when reading the contents!)

function (req, res) {
    var dir = req.params.path // probably never used, but bear with me...
    return dir2json(dir).pipe(res);
}

or similar

feltnerm avatar Nov 12 '13 21:11 feltnerm