Skip to content

Commit

Permalink
Merge pull request #29 from bchelli/readlargedir
Browse files Browse the repository at this point in the history
Read large directories
  • Loading branch information
bchelli authored Oct 4, 2018
2 parents a90b399 + 8cdf0b3 commit 725590f
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 46 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ This function will close the open connection if opened, it will be called automa
- [Benjamin Chelli](https://github.com/bchelli)
- [Fabrice Marsaud](https://github.com/marsaud)
- [Jay McAliley](https://github.com/jaymcaliley)
- [eldrago](https://github.com/eldrago)

## References

Expand Down
52 changes: 41 additions & 11 deletions lib/api/readdir.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,50 @@ module.exports = function(path, cb){
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
else queryDir(file, connection, [], cb);
});
}





/*
* Helpers
*/

/**
* queryDir - recursive querying until all files in a directory have been added to the listing.
* @param file
* @param connection
* @param completeFileListing
* @param cb
*/
function queryDir(file, connection, completeFileListing, cb) {
SMB2Request('query_directory', file, connection, function(err, files){
var allFiles = completeFileListing.concat(files || []);

// no more file
// => close and send response
if(err && err.code === 'STATUS_NO_MORE_FILES') {
return SMB2Request('close', file, connection, function(err){
var fileNames = allFiles
.map(function(v){ return v.Filename }) // get the filename only
.filter(function(v){ return v!='.' && v!='..' }) // remove '.' and '..' values
);
;
cb && cb(null, fileNames);
});
});
}

// error
// => close and send error
if (err) {
return cb && cb(err);
}

// still receiving files
// => maybe the folder is not empty
queryDir(file, connection, allFiles, cb)
});

}


4 changes: 3 additions & 1 deletion lib/tools/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ var defaults = {
, self.parseResponse && self.parseResponse(response)
);
} else {
cb && cb(new Error(MsErref.getErrorMessage(err)));
var error = new Error(MsErref.getErrorMessage(err));
error.code = err.code;
cb && cb(error);
}
};

Expand Down
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 25 additions & 34 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,39 +1,30 @@
{

"name":"smb2"
, "description":"SMB2 Client"
, "homepage": "https://github.com/bchelli/node-smb2"

, "version":"0.2.8"

, "engines": [
"name": "smb2",
"description": "SMB2 Client",
"homepage": "https://github.com/bchelli/node-smb2",
"version": "0.2.8",
"engines": [
"node"
]

, "author":{
"name": "Benjamin Chelli"
, "email": "[email protected]"
, "url": "https://github.com/bchelli"
}

, "main":"lib/smb2.js"

, "repository": {
"type": "git"
, "url": "https://github.com/bchelli/node-smb2"
}

, "dependencies": {
],
"author": {
"name": "Benjamin Chelli",
"email": "[email protected]",
"url": "https://github.com/bchelli"
},
"main": "lib/smb2.js",
"repository": {
"type": "git",
"url": "https://github.com/bchelli/node-smb2"
},
"dependencies": {
"ntlm": "~0.1.1"
}

, "keywords": [
"SMB"
, "SMB2"
, "SMB3"
, "NTLM"
, "CIFS"
, "Samba"
},
"keywords": [
"SMB",
"SMB2",
"SMB3",
"NTLM",
"CIFS",
"Samba"
]

}

0 comments on commit 725590f

Please sign in to comment.