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 SMB2Forge = require('../tools/smb2-forge');
var SMB2Request = SMB2Forge.request; var SMB2Request = SMB2Forge.request;
var BigInt = require('../tools/bigint'); var BigInt = require('../tools/bigint');
var constants = require('../structures/constants');
/* /*
* writeFile * writeFile
...@@ -23,6 +24,16 @@ module.exports = function writeFile(filename, data, options, cb) { ...@@ -23,6 +24,16 @@ module.exports = function writeFile(filename, data, options, cb) {
options = {}; 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'; options.encoding = options.encoding || 'utf8';
var connection = this; var connection = this;
...@@ -33,14 +44,19 @@ module.exports = function writeFile(filename, data, options, cb) { ...@@ -33,14 +44,19 @@ module.exports = function writeFile(filename, data, options, cb) {
var fileLength = new BigInt(8, fileContent.length); var fileLength = new BigInt(8, fileContent.length);
function createFile(fileCreated) { function createFile(fileCreated) {
SMB2Request('create', { path: filename }, connection, function(err, f) { SMB2Request(
if (err) cb && cb(err); 'create',
// SMB2 set file size { createDisposition: createDisposition, path: filename },
else { connection,
file = f; function(err, f) {
fileCreated(); if (err) cb && cb(err);
// SMB2 set file size
else {
file = f;
fileCreated();
}
} }
}); );
} }
function closeFile(fileClosed) { 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