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
1796d6b7
Commit
1796d6b7
authored
May 07, 2019
by
HamadaBrest
Committed by
Julien Fontanet
May 07, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: new truncate method (#43)
parent
2c08c9a7
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
68 additions
and
1 deletion
+68
-1
README.md
README.md
+17
-0
RELEASE.md
RELEASE.md
+3
-0
lib/api/truncate.js
lib/api/truncate.js
+38
-0
lib/messages/open.js
lib/messages/open.js
+1
-1
lib/smb2.js
lib/smb2.js
+3
-0
lib/structures/constants.js
lib/structures/constants.js
+6
-0
No files found.
README.md
View file @
1796d6b7
...
...
@@ -217,6 +217,23 @@ smb2Client.writeFile('path\\to\\my\\file.txt', 'Hello Node', function(err) {
});
```
> `smb2Client.truncate ( filename, length, callback )`
-
`filename`
String
-
`length`
Number
-
`callback`
Function
Asynchronously truncate a file to a size of precisely length bytes.
Example:
```
javascript
smb2Client
.
truncate
(
'
path
\\
to
\\
my
\\
file.txt
'
,
10
,
function
(
err
)
{
if
(
err
)
throw
err
;
console
.
log
(
"
It's truncated!
"
);
});
```
### Streams
> `smb2Client.createReadStream ( fileName, [options], callback )`
...
...
RELEASE.md
View file @
1796d6b7
# Releases
## 0.14.0
-
smb2.truncate
## 0.4.0
-
smb2.ensureDir
...
...
lib/api/truncate.js
0 → 100644
View file @
1796d6b7
var
SMB2Forge
=
require
(
'
../tools/smb2-forge
'
);
var
SMB2Request
=
SMB2Forge
.
request
;
var
BigInt
=
require
(
'
../tools/bigint
'
);
var
FILE_WRITE_DATA
=
require
(
'
../structures/constants
'
).
FILE_WRITE_DATA
;
function
setFileSize
(
file
,
fileLength
,
connection
,
cb
)
{
SMB2Request
(
'
set_info
'
,
{
FileId
:
file
.
FileId
,
FileInfoClass
:
'
FileEndOfFileInformation
'
,
Buffer
:
fileLength
.
toBuffer
(),
},
connection
,
cb
);
}
module
.
exports
=
function
truncate
(
path
,
length
,
cb
)
{
var
connection
=
this
;
SMB2Request
(
'
open
'
,
{
path
:
path
,
desiredAccess
:
FILE_WRITE_DATA
},
connection
,
function
(
err
,
file
)
{
if
(
err
!=
null
)
{
return
cb
(
err
);
}
setFileSize
(
file
,
new
BigInt
(
8
,
length
),
connection
,
function
(
err
)
{
SMB2Request
(
'
close
'
,
file
,
connection
,
function
()
{
cb
(
err
);
});
});
}
);
};
lib/messages/open.js
View file @
1796d6b7
...
...
@@ -4,7 +4,6 @@ var message = require('../tools/message');
module
.
exports
=
message
({
generate
:
function
(
connection
,
params
)
{
var
buffer
=
Buffer
.
from
(
params
.
path
,
'
ucs2
'
);
return
new
SMB2Message
({
headers
:
{
Command
:
'
CREATE
'
,
...
...
@@ -16,6 +15,7 @@ module.exports = message({
Buffer
:
buffer
,
NameOffset
:
0x0078
,
CreateContextsOffset
:
0x007a
+
buffer
.
length
,
DesiredAccess
:
params
.
desiredAccess
,
},
});
},
...
...
lib/smb2.js
View file @
1796d6b7
...
...
@@ -136,3 +136,6 @@ proto.write = autoPromise(require('./api/write'), function(
};
});
proto
.
close
=
autoPromise
(
require
(
'
./api/close
'
));
proto
.
truncate
=
autoPromise
(
SMB2Connection
.
requireConnect
(
require
(
'
./api/truncate
'
))
);
lib/structures/constants.js
View file @
1796d6b7
...
...
@@ -13,4 +13,10 @@ module.exports = {
// Where do they come from?!
MAX_READ_LENGTH
:
0x00010000
,
MAX_WRITE_LENGTH
:
0x00010000
-
0x71
,
/**
* 2.2.13.1.1 SMB2 File_Pipe_Printer_Access_Mask
* https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-smb2/77b36d0f-6016-458a-a7a0-0f4a72ae1534
*/
FILE_WRITE_DATA
:
0x00000002
,
};
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