From 483632eb650402cc7730272dfaee37443f599808 Mon Sep 17 00:00:00 2001 From: Anson Wayman Date: Mon, 1 Aug 2016 09:12:42 -0600 Subject: [PATCH 1/2] Added readdirextra to expose raw file properties Was not sure about the naming convention for this particular function, but I have a great need to read particular file properties on individual files without loading the entire file into memory. I added a new function so as not to break backwards compatibility of this package. I did not add any logic to parse these individual file properties, as I know things like times and dates are stored differently or mean different things between operating systems. --- lib/api/readdirextra.js | 40 ++++++++++++++++++++++++++++++++++++++++ lib/smb2.js | 1 + 2 files changed, 41 insertions(+) create mode 100644 lib/api/readdirextra.js diff --git a/lib/api/readdirextra.js b/lib/api/readdirextra.js new file mode 100644 index 0000000..b9df7af --- /dev/null +++ b/lib/api/readdirextra.js @@ -0,0 +1,40 @@ + + +var SMB2Forge = require('../tools/smb2-forge') + , SMB2Request = SMB2Forge.request + ; + +/* + * readdirextra + * ======= + * + * list the file / directory and file data from the path provided: + * + * - open the directory + * + * - query directory content + * + * - close the directory + * + */ +module.exports = function(path, cb){ + var connection = this; + + // SMB2 open directory + SMB2Request('open', {path:path}, connection, function(err, file){ + if(err) cb && cb(err); + // SMB2 query directory + else SMB2Request('query_directory', file, connection, function(err, files){ + if(err) cb && cb(err); + // SMB2 close directory + else SMB2Request('close', file, connection, function(err){ + cb && cb( + null + , files + ); + }); + }); + }); +} + + diff --git a/lib/smb2.js b/lib/smb2.js index 5b34789..e0d8288 100644 --- a/lib/smb2.js +++ b/lib/smb2.js @@ -98,6 +98,7 @@ proto.writeFile = SMB2Connection.requireConnect(require('./api/writefile')); proto.unlink = SMB2Connection.requireConnect(require('./api/unlink')); proto.readdir = SMB2Connection.requireConnect(require('./api/readdir')); +proto.readdirextra = SMB2Connection.requireConnect(require('./api/readdirextra')); proto.rmdir = SMB2Connection.requireConnect(require('./api/rmdir')); proto.mkdir = SMB2Connection.requireConnect(require('./api/mkdir')); From 6722772a6adeef4f3935defd75779726c870fc71 Mon Sep 17 00:00:00 2001 From: Anson Wayman Date: Mon, 1 Aug 2016 09:28:45 -0600 Subject: [PATCH 2/2] Updated README.md with proposed function --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index d463e1a..a624126 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,17 @@ smb2Client.readdir('Windows\\System32', function(err, files){ }); ``` +### smb2Client.readdirextra ( path, callback ) +Asynchronous readdir(3). Reads the contents of a directory. The callback gets two arguments (err, files) where files is an array of objects representing all files and their properties in the directory, including '.' and '..'. + +Example: +```javascript +smb2Client.readdirextra('Windows\\System32', function(err, files){ + if(err) throw err; + console.log(files); +}); +``` + ### smb2Client.readFile ( filename, [options], callback ) - ```filename``` String - ```options``` Object