Commit 70513a34 authored by Julien Fontanet's avatar Julien Fontanet

feat(writeFile): support flags

`flag` option is also supported for `fs` compatibility
parent f30bfccc
var SMB2Forge = require('../tools/smb2-forge');
var SMB2Request = SMB2Forge.request;
var BigInt = require('../tools/bigint');
var constants = require('../structures/constants');
/*
* writeFile
......@@ -23,6 +24,16 @@ module.exports = function writeFile(filename, data, options, cb) {
options = {};
}
var createDisposition;
var flags = options != null && (options.flags || options.flag);
if (flags === 'r+') {
createDisposition = constants.FILE_OPEN;
} else if (flags === 'w' || flags === 'w+') {
createDisposition = constants.FILE_OVERWRITE_IF;
} else if (flags === 'wx' || flags === 'wx+') {
createDisposition = constants.FILE_CREATE;
}
options.encoding = options.encoding || 'utf8';
var connection = this;
......@@ -33,14 +44,19 @@ module.exports = function writeFile(filename, data, options, cb) {
var fileLength = new BigInt(8, fileContent.length);
function createFile(fileCreated) {
SMB2Request('create', { path: filename }, connection, function(err, f) {
if (err) cb && cb(err);
// SMB2 set file size
else {
file = f;
fileCreated();
SMB2Request(
'create',
{ createDisposition: createDisposition, path: filename },
connection,
function(err, f) {
if (err) cb && cb(err);
// SMB2 set file size
else {
file = f;
fileCreated();
}
}
});
);
}
function closeFile(fileClosed) {
......
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