Commit c27eaa4c authored by Julien Fontanet's avatar Julien Fontanet

fix(read): various issues

parent 77f48dc0
......@@ -4,39 +4,39 @@ var BigInt = require('../tools/bigint');
var request = require('../tools/smb2-forge').request;
var MAX_READ_LENGTH = require('../structures/constants').MAX_READ_LENGTH;
module.exports = function read(file, buffer, offset, length, position, cb) {
assert(position !== null, 'null position is not supported');
module.exports = function read(file, buffer, offset, length, start, cb) {
assert(pos !== null, 'null pos is not supported');
var fileSize = BigInt.fromBuffer(file.EndofFile);
var bytesRead = 0;
var connection = this;
position = new BigInt(8, position);
var end = Math.min(
start + length,
BigInt.fromBuffer(file.EndofFile).toNumber()
);
var pos = start;
function onRead(err, chunk) {
if (err != null) {
return cb(err, bytesRead, buffer);
return cb(err, pos - start, buffer);
}
chunk.copy(buffer, offset);
var n = chunk.length;
bytesRead += n;
offset += n;
position = position.add(n);
pos += n;
readChunk();
}
function readChunk() {
if (bytesRead >= length || position.ge(fileSize)) {
return cb(null, bytesRead, buffer);
if (pos >= end) {
return cb(null, pos - start, buffer);
}
request(
'read',
{
FileId: file.FileId,
Length: Math.min(MAX_READ_LENGTH, length - bytesRead),
Offset: position.toBuffer(),
Length: Math.min(MAX_READ_LENGTH, end - pos),
Offset: new BigInt(8, pos).toBuffer(),
},
connection,
onRead
......
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