Commit d0f1671e authored by Julien Fontanet's avatar Julien Fontanet

chore: remove Bluebird dep

parent 2c009a43
...@@ -3,6 +3,9 @@ module.exports = { ...@@ -3,6 +3,9 @@ module.exports = {
"node": true "node": true
}, },
"extends": "eslint:recommended", "extends": "eslint:recommended",
"globals": {
"Promise": true
},
"parserOptions": { "parserOptions": {
"ecmaVersion": 5 "ecmaVersion": 5
}, },
......
import Bigint from '../tools/bigint'; import Bigint from '../tools/bigint';
import Bluebird from 'bluebird';
import { Readable } from 'stream'; import { Readable } from 'stream';
import { request } from '../tools/smb2-forge'; import { request } from '../tools/smb2-forge';
const requestAsync = Bluebird.promisify(request);
const maxPacketSize = 0x00010000; const maxPacketSize = 0x00010000;
class SmbReadableStream extends Readable { class SmbReadableStream extends Readable {
...@@ -40,7 +37,7 @@ class SmbReadableStream extends Readable { ...@@ -40,7 +37,7 @@ class SmbReadableStream extends Readable {
const offset = new Bigint(this.offset); const offset = new Bigint(this.offset);
this.wait = true; this.wait = true;
let content = await requestAsync( let content = await request(
'read', 'read',
{ {
FileId: this.file.FileId, FileId: this.file.FileId,
...@@ -62,7 +59,7 @@ class SmbReadableStream extends Readable { ...@@ -62,7 +59,7 @@ class SmbReadableStream extends Readable {
} }
if (this.offset.ge(this.fileLength)) { if (this.offset.ge(this.fileLength)) {
this.push(null); this.push(null);
await requestAsync('close', this.file, this.connection); await request('close', this.file, this.connection);
} }
} }
} }
......
import Bigint from '../tools/bigint'; import Bigint from '../tools/bigint';
import Bluebird from 'bluebird';
import { request } from '../tools/smb2-forge'; import { request } from '../tools/smb2-forge';
import { Writable } from 'stream'; import { Writable } from 'stream';
...@@ -10,8 +9,6 @@ import { ...@@ -10,8 +9,6 @@ import {
FILE_CREATE, FILE_CREATE,
} from '../structures/constants'; } from '../structures/constants';
const requestAsync = Bluebird.promisify(request);
const maxPacketSize = new Bigint(8, 0x00010000 - 0x71); const maxPacketSize = new Bigint(8, 0x00010000 - 0x71);
function* fibonacci() { function* fibonacci() {
...@@ -54,7 +51,7 @@ class SmbWritableStream extends Writable { ...@@ -54,7 +51,7 @@ class SmbWritableStream extends Writable {
while (pending) { while (pending) {
try { try {
await requestAsync( await request(
'write', 'write',
{ {
FileId: this.file.FileId, FileId: this.file.FileId,
...@@ -84,7 +81,7 @@ class SmbWritableStream extends Writable { ...@@ -84,7 +81,7 @@ class SmbWritableStream extends Writable {
try { try {
super.end(...args); super.end(...args);
} finally { } finally {
await requestAsync('close', this.file, this.connection); await request('close', this.file, this.connection);
} }
} }
} }
......
import { request } from '../tools/smb2-forge'; import { request } from '../tools/smb2-forge';
import Bluebird from 'bluebird';
const requestAsync = Bluebird.promisify(request);
const ensureOneDir = async function(path, connection) { const ensureOneDir = async function(path, connection) {
try { try {
const fileOrDir = await requestAsync('open', { path }, connection); const fileOrDir = await request('open', { path }, connection);
if (fileOrDir.FileAttributes.readIntBE(0, 1) === 0x00000010) { if (fileOrDir.FileAttributes.readIntBE(0, 1) === 0x00000010) {
// See http://download.microsoft.com/DOWNLOAD/9/5/E/95EF66AF-9026-4BB0-A41D-A4F81802D92C/[MS-FSCC].pdf Section 2.6 // See http://download.microsoft.com/DOWNLOAD/9/5/E/95EF66AF-9026-4BB0-A41D-A4F81802D92C/[MS-FSCC].pdf Section 2.6
await requestAsync('close', fileOrDir, connection); await request('close', fileOrDir, connection);
} else { } else {
throw new Error(`${path} exists but is not a directory`); throw new Error(`${path} exists but is not a directory`);
} }
} catch (err) { } catch (err) {
if (err.code === 'STATUS_OBJECT_NAME_NOT_FOUND') { if (err.code === 'STATUS_OBJECT_NAME_NOT_FOUND') {
try { try {
await requestAsync('create_folder', { path }, connection); await request('create_folder', { path }, connection);
} catch (err) { } catch (err) {
if (err.code !== 'STATUS_OBJECT_NAME_COLLISION') { if (err.code !== 'STATUS_OBJECT_NAME_COLLISION') {
throw err; throw err;
......
...@@ -17,11 +17,24 @@ SMB2Forge.request = function(messageName, params, connection, cb) { ...@@ -17,11 +17,24 @@ SMB2Forge.request = function(messageName, params, connection, cb) {
// send // send
sendNetBiosMessage(connection, smbMessage); sendNetBiosMessage(connection, smbMessage);
// wait for the response // wait for the response
var promise;
if (cb === undefined) {
promise = new Promise(function(resolve, reject) {
cb = function(err, result) {
if (err == null) {
resolve(result);
} else {
reject(err);
}
};
});
}
getResponse( getResponse(
connection, connection,
smbMessage.getHeaders().MessageId, smbMessage.getHeaders().MessageId,
msg.parse(connection, cb) msg.parse(connection, cb)
); );
return promise;
}; };
/* /*
......
...@@ -21,7 +21,6 @@ ...@@ -21,7 +21,6 @@
}, },
"dependencies": { "dependencies": {
"babel-runtime": "^5.8.34", "babel-runtime": "^5.8.34",
"bluebird": "^2.10.2",
"ntlm": "~0.1.1" "ntlm": "~0.1.1"
}, },
"keywords": [ "keywords": [
......
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