Commit 889a7bdd authored by wescoeur's avatar wescoeur Committed by Fabrice Marsaud

WriteStream supports r, r+, w, w+ options.

parent 0da311ce
......@@ -69,4 +69,4 @@ function renameBuffer (newPath) {
]);
}
\ No newline at end of file
}
......@@ -3,6 +3,12 @@ import Bluebird from 'bluebird'
import {request} from '../tools/smb2-forge'
import {Writable} from 'stream'
import {
FILE_OPEN,
FILE_OPEN_IF,
FILE_OVERWRITE_IF
} from '../structures/constants'
const requestAsync = Bluebird.promisify(request)
const maxPacketSize = new Bigint(8, 0x00010000 - 0x71)
......@@ -86,7 +92,19 @@ export default function (path, options, cb) {
cb = options
options = {}
}
request('create', {path}, this, (err, file) => {
let createDisposition
const flags = options && options.flags
if (flags === 'r') {
createDisposition = FILE_OPEN
} else if (flags === 'r+') {
createDisposition = FILE_OPEN_IF
} else if (flags === 'w' || flags === 'w+') {
createDisposition = FILE_OVERWRITE_IF
}
request('create', { path, createDisposition }, this, (err, file) => {
if (err) {
cb(err)
} else {
......
var SMB2Message = require('../tools/smb2-message')
, message = require('../tools/message')
;
var message = require('../tools/message')
var FILE_OVERWRITE_IF = require('../structures/constants').FILE_OVERWRITE_IF
module.exports = message({
generate:function(connection, params){
var buffer = new Buffer(params.path, 'ucs2');
var createDisposition = params.createDisposition
if (!(createDisposition >= 0 && createDisposition <= 5)) {
createDisposition = FILE_OVERWRITE_IF
}
return new SMB2Message({
headers:{
......@@ -23,7 +25,7 @@ module.exports = message({
, 'DesiredAccess':0x001701DF
, 'FileAttributes':0x00000080
, 'ShareAccess':0x00000000
, 'CreateDisposition':0x00000005
, 'CreateDisposition': createDisposition
, 'CreateOptions':0x00000044
, 'NameOffset':0x0078
, 'CreateContextsOffset':0x007A+buffer.length
......
module.exports = {
FILE_SUPERSEDE: 0x00000000,
FILE_OPEN: 0x00000001,
FILE_CREATE: 0x00000002,
FILE_OPEN_IF: 0x00000003,
FILE_OVERWRITE: 0x00000004,
FILE_OVERWRITE_IF: 0x00000005
}
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