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
4a04585f
Commit
4a04585f
authored
Jul 10, 2018
by
Julien Fontanet
Committed by
GitHub
Jul 10, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore(createReadStream): rewrite in ES5 (#25)
parent
bce42048
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
83 additions
and
85 deletions
+83
-85
lib/api/createReadStream.js
lib/api/createReadStream.js
+83
-0
lib/api/src/createReadStream.js
lib/api/src/createReadStream.js
+0
-85
No files found.
lib/api/createReadStream.js
0 → 100644
View file @
4a04585f
var
Readable
=
require
(
'
stream
'
).
Readable
;
var
BigInt
=
require
(
'
../tools/bigint
'
);
var
request
=
require
(
'
../tools/smb2-forge
'
).
request
;
// Where does it come from?!
var
maxPacketSize
=
0x00010000
;
module
.
exports
=
function
createReadStream
(
path
,
options
,
cb
)
{
if
(
typeof
options
===
'
function
'
)
{
cb
=
options
;
options
=
{};
}
else
if
(
options
==
null
)
{
options
=
{}
}
var
connection
=
this
;
request
(
'
open
'
,
{
path
:
path
},
connection
,
function
(
err
,
file
)
{
if
(
err
!=
null
)
{
return
cb
(
err
);
}
var
offset
=
new
BigInt
(
file
.
EndofFile
.
length
,
options
.
start
||
0
);
var
fileSize
=
BigInt
.
fromBuffer
(
file
.
EndofFile
);
var
end
=
options
.
end
if
(
end
!=
null
)
{
end
=
new
BigInt
(
8
,
end
+
1
)
if
(
end
.
gt
(
fileSize
))
{
fileSize
=
end
}
}
var
close
=
request
.
bind
(
undefined
,
'
close
'
,
file
,
connection
);
var
stream
=
new
Readable
();
stream
.
_destroy
=
function
(
err
,
cb
)
{
close
(
function
(
err2
)
{
if
(
err
!=
null
)
{
return
cb
(
err2
);
}
cb
(
err
);
});
};
var
running
=
false
;
stream
.
_read
=
function
(
size
)
{
if
(
running
)
{
return
;
}
if
(
offset
.
ge
(
fileSize
))
{
return
close
(
function
()
{
this
.
push
(
null
)
})
}
running
=
true
;
request
(
'
read
'
,
{
FileId
:
file
.
FileId
,
Length
:
Math
.
min
(
maxPacketSize
,
size
),
Offset
:
offset
.
toBuffer
(),
},
connection
,
function
(
err
,
content
)
{
try
{
if
(
err
!=
null
)
{
return
process
.
nextTick
(
stream
.
emit
.
bind
(
stream
,
'
error
'
,
err
));
}
offset
=
offset
.
add
(
content
.
length
);
stream
.
push
(
content
);
}
finally
{
running
=
false
;
}
}
);
};
cb
(
null
,
stream
);
});
};
lib/api/src/createReadStream.js
deleted
100644 → 0
View file @
bce42048
import
Bigint
from
'
../tools/bigint
'
;
import
Bluebird
from
'
bluebird
'
;
import
{
Readable
}
from
'
stream
'
;
import
{
request
}
from
'
../tools/smb2-forge
'
;
const
requestAsync
=
Bluebird
.
promisify
(
request
);
const
maxPacketSize
=
0x00010000
;
class
SmbReadableStream
extends
Readable
{
constructor
(
connection
,
file
,
options
=
{})
{
super
(
options
);
const
{
start
=
0
,
end
,
encoding
}
=
options
;
this
.
connection
=
connection
;
this
.
encoding
=
encoding
;
this
.
file
=
file
;
this
.
offset
=
new
Bigint
(
8
,
start
);
let
fileLength
=
0
;
for
(
let
i
=
0
;
i
<
file
.
EndofFile
.
length
;
i
++
)
{
fileLength
+=
file
.
EndofFile
[
i
]
*
Math
.
pow
(
2
,
i
*
8
);
}
this
.
fileLength
=
fileLength
;
this
.
wait
=
false
;
if
(
end
>=
0
&&
end
<
fileLength
)
{
this
.
fileLength
=
end
+
1
;
}
}
async
_read
(
size
)
{
while
(
this
.
offset
.
lt
(
this
.
fileLength
)
/* && size > 0*/
)
{
if
(
this
.
wait
)
{
return
;
}
const
rest
=
this
.
offset
.
sub
(
this
.
fileLength
).
neg
();
const
packetSize
=
Math
.
min
(
maxPacketSize
,
rest
.
toNumber
()
/*, size*/
);
const
offset
=
new
Bigint
(
this
.
offset
);
this
.
wait
=
true
;
let
content
=
await
requestAsync
(
'
read
'
,
{
FileId
:
this
.
file
.
FileId
,
Length
:
packetSize
,
Offset
:
offset
.
toBuffer
(),
},
this
.
connection
);
this
.
wait
=
false
;
if
(
this
.
encoding
)
{
content
=
content
.
toString
(
this
.
encoding
);
}
this
.
offset
=
this
.
offset
.
add
(
packetSize
);
// size -= packetSize
if
(
!
this
.
push
(
content
))
{
return
;
}
}
if
(
this
.
offset
.
ge
(
this
.
fileLength
))
{
this
.
push
(
null
);
await
requestAsync
(
'
close
'
,
this
.
file
,
this
.
connection
);
}
}
}
export
default
function
(
path
,
options
,
cb
)
{
if
(
typeof
options
===
'
function
'
)
{
cb
=
options
;
options
=
{};
}
request
(
'
open
'
,
{
path
},
this
,
(
err
,
file
)
=>
{
if
(
err
)
{
if
(
err
.
code
===
'
STATUS_OBJECT_NAME_NOT_FOUND
'
)
{
err
.
code
=
'
ENOENT
'
;
}
cb
(
err
);
}
else
{
cb
(
null
,
new
SmbReadableStream
(
this
,
file
,
options
));
}
});
}
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