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

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

parent 0da311ce
...@@ -3,6 +3,12 @@ import Bluebird from 'bluebird' ...@@ -3,6 +3,12 @@ import Bluebird from 'bluebird'
import {request} from '../tools/smb2-forge' import {request} from '../tools/smb2-forge'
import {Writable} from 'stream' import {Writable} from 'stream'
import {
FILE_OPEN,
FILE_OPEN_IF,
FILE_OVERWRITE_IF
} from '../structures/constants'
const requestAsync = Bluebird.promisify(request) const requestAsync = Bluebird.promisify(request)
const maxPacketSize = new Bigint(8, 0x00010000 - 0x71) const maxPacketSize = new Bigint(8, 0x00010000 - 0x71)
...@@ -86,7 +92,19 @@ export default function (path, options, cb) { ...@@ -86,7 +92,19 @@ export default function (path, options, cb) {
cb = options cb = options
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) { if (err) {
cb(err) cb(err)
} else { } else {
......
var SMB2Message = require('../tools/smb2-message') 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({ module.exports = message({
generate:function(connection, params){ generate:function(connection, params){
var buffer = new Buffer(params.path, 'ucs2'); var buffer = new Buffer(params.path, 'ucs2');
var createDisposition = params.createDisposition
if (!(createDisposition >= 0 && createDisposition <= 5)) {
createDisposition = FILE_OVERWRITE_IF
}
return new SMB2Message({ return new SMB2Message({
headers:{ headers:{
...@@ -23,7 +25,7 @@ module.exports = message({ ...@@ -23,7 +25,7 @@ module.exports = message({
, 'DesiredAccess':0x001701DF , 'DesiredAccess':0x001701DF
, 'FileAttributes':0x00000080 , 'FileAttributes':0x00000080
, 'ShareAccess':0x00000000 , 'ShareAccess':0x00000000
, 'CreateDisposition':0x00000005 , 'CreateDisposition': createDisposition
, 'CreateOptions':0x00000044 , 'CreateOptions':0x00000044
, 'NameOffset':0x0078 , 'NameOffset':0x0078
, 'CreateContextsOffset':0x007A+buffer.length , '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