Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
Marsaud Smb2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nanahira
Marsaud Smb2
Commits
215cb2be
Commit
215cb2be
authored
Dec 08, 2018
by
Julien Fontanet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(write): low level write method
parent
97a9273e
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
62 additions
and
6 deletions
+62
-6
lib/api/createWriteStream.js
lib/api/createWriteStream.js
+1
-4
lib/api/write.js
lib/api/write.js
+58
-0
lib/api/writeFile.js
lib/api/writeFile.js
+1
-1
lib/structures/constants.js
lib/structures/constants.js
+2
-1
No files found.
lib/api/createWriteStream.js
View file @
215cb2be
...
...
@@ -4,9 +4,6 @@ var BigInt = require('../tools/bigint');
var
parseFlags
=
require
(
'
../tools/parse-flags
'
);
var
request
=
require
(
'
../tools/smb2-forge
'
).
request
;
// Where does it come from?!
var
maxPacketSize
=
0x00010000
-
0x71
;
module
.
exports
=
function
createWriteStream
(
path
,
options
,
cb
)
{
if
(
typeof
options
===
'
function
'
)
{
cb
=
options
;
...
...
@@ -31,7 +28,7 @@ module.exports = function createWriteStream(path, options, cb) {
var
close
=
request
.
bind
(
undefined
,
'
close
'
,
file
,
connection
);
function
write
(
buffer
,
i
,
cb
)
{
var
j
=
i
+
maxPacketSize
;
var
j
=
i
+
constants
.
MAX_WRITE_LENGTH
;
var
chunk
=
buffer
.
slice
(
i
,
j
);
request
(
'
write
'
,
...
...
lib/api/write.js
0 → 100644
View file @
215cb2be
var
assert
=
require
(
'
assert
'
);
var
BigInt
=
require
(
'
../tools/bigint
'
);
var
request
=
require
(
'
../tools/smb2-forge
'
).
request
;
var
MAX_WRITE_LENGTH
=
require
(
'
../structures/constants
'
).
MAX_WRITE_LENGTH
;
module
.
exports
=
function
write
(
file
,
buffer
,
offset
,
length
,
start
,
cb
)
{
assert
(
Buffer
.
isBuffer
(
buffer
));
if
(
offset
===
undefined
)
{
offset
=
0
;
}
else
{
assert
(
typeof
offset
===
'
number
'
);
assert
(
offset
>
0
);
assert
(
offset
<
buffer
.
length
);
}
if
(
length
===
undefined
)
{
length
=
buffer
.
length
-
offset
;
}
else
{
assert
(
typeof
length
===
'
number
'
);
assert
(
length
>
0
);
length
=
Math
.
min
(
length
,
buffer
.
length
-
offset
);
}
assert
(
typeof
start
===
'
number
'
);
var
connection
=
this
;
var
pos
=
start
;
var
chunkLength
;
function
onWrite
(
err
)
{
if
(
err
!=
null
)
{
return
cb
(
err
,
pos
-
start
,
buffer
);
}
offset
+=
chunkLength
;
pos
+=
chunkLength
;
writeChunk
();
}
function
writeChunk
()
{
if
(
length
<=
0
)
{
cb
(
null
,
length
);
}
chunkLength
=
Math
.
min
(
MAX_WRITE_LENGTH
,
length
);
request
(
'
write
'
,
{
Buffer
:
buffer
.
slice
(
offset
,
offset
+
chunkLength
),
FileId
:
file
.
FileId
,
Offset
:
new
BigInt
(
8
,
pos
).
toBuffer
(),
},
connection
,
onWrite
);
}
process
.
nextTick
(
writeChunk
);
};
lib/api/writeFile.js
View file @
215cb2be
...
...
@@ -84,7 +84,7 @@ module.exports = function writeFile(filename, data, options, cb) {
var
offset
=
new
BigInt
(
8
);
var
stop
=
false
;
var
nbRemainingPackets
=
0
;
var
maxPacketSize
=
new
BigInt
(
8
,
0x00010000
-
0x71
);
var
maxPacketSize
=
new
BigInt
(
8
,
constants
.
MAX_WRITE_LENGTH
);
// callback manager
function
callback
()
{
return
function
(
err
)
{
...
...
lib/structures/constants.js
View file @
215cb2be
...
...
@@ -10,6 +10,7 @@ module.exports = {
FILE_OVERWRITE
:
0x00000004
,
FILE_OVERWRITE_IF
:
0x00000005
,
// Where do
es it
come from?!
// Where do
they
come from?!
MAX_READ_LENGTH
:
0x00010000
,
MAX_WRITE_LENGTH
:
0x00010000
-
0x71
,
};
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment