Commit ee5074c2 authored by Benjamin Chelli's avatar Benjamin Chelli

Add mkdir function in the API

parent ffecf15e
......@@ -87,6 +87,17 @@ smb2Client.writeFile('path\\to\\my\\file.txt', 'Hello Node', function (err) {
});
```
### smb2Client.mkdir ( path, [mode], callback )
Asynchronous mkdir(2). No arguments other than a possible exception are given to the completion callback. mode defaults to 0777.
Example:
```javascript
smb2Client.mkdir('path\\to\\the\\folder', function (err) {
if (err) throw err;
console.log('Folder created saved!');
});
```
### smb2Client.exists ( path, callback )
Test whether or not the given path exists by checking with the file system. Then call the callback argument with either true or false. Example:
```javascript
......
var SMB2Message = require('../message')
, message = require('../tools/message')
;
module.exports = message({
generate:function(connection, params){
var buffer = new Buffer(params.path, 'ucs2');
return new SMB2Message({
headers:{
'Command':'CREATE'
, 'SessionId':connection.SessionId
, 'TreeId':connection.TreeId
}
, request:{
'Buffer':buffer
, 'DesiredAccess':0x001701DF
, 'FileAttributes':0x00000000
, 'ShareAccess':0x00000000
, 'CreateDisposition':0x00000002
, 'CreateOptions':0x00000021
, 'NameOffset':0x0078
, 'CreateContextsOffset':0x007A+buffer.length
}
});
}
});
......@@ -432,6 +432,58 @@ proto.unlink = function(path, cb){
}
/*
* mkdir
* =====
*
* create folder:
*
* - open the file
*
* - remove the file
*
* - close the file
*
*/
proto.mkdir = function(path, mode, cb){
if(typeof mode == 'function'){
cb = mode;
mode = '0777';
}
var connection = this;
connect(connection, function(err){
cb = scheduleAutoClose(connection, cb);
if(err) cb(err);
else connection.exists(path, function(err, exists){
if(err) cb && cb(err);
else if(!exists){
// SMB2 open file
SMB2Request('create-folder', {path:path}, connection, function(err, file){
if(err) cb && cb(err);
// SMB2 query directory
else SMB2Request('close', file, connection, function(err){
cb && cb(null);
});
});
} else {
cb(new Error('File/Folder already exists'));
}
});
});
}
/*
* PRIVATE FUNCTION TO HANDLE CONNECTION
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment