Skip to content

Commit

Permalink
feat(Bluebird Removal): Migrate detect function to native promises (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
Thexumaker authored Aug 21, 2022
1 parent ab790e6 commit 605eede
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
22 changes: 10 additions & 12 deletions lib/detect.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
'use strict';

var fs = require('fs');
var Promise = require('bluebird');
var pread = Promise.promisify(fs.read, { multiArgs: true });
var util = require('util');
var pread = util.promisify(fs.read);

var DETECT_LENGTH = 16;

//Determines the appropriate plugin to use for the given file descriptor.
module.exports = function (fd, plugins) {
return pread(fd, Buffer.alloc(DETECT_LENGTH), 0, DETECT_LENGTH, 0)
.spread(function (bytesRead, buffer) {
for (var i = 0; i < plugins.length; i++) {
var plugin = plugins[i];
if (plugin.detect(buffer)) {
return plugin;
}
module.exports = async function (fd, plugins) {
const readObject = await pread(fd, Buffer.alloc(DETECT_LENGTH), 0, DETECT_LENGTH, 0);
for (var i = 0; i < plugins.length; i++) {
var plugin = plugins[i];
if (plugin.detect(readObject.buffer)) {
return plugin;
}
throw new Error('File type not supported');
});
}
throw new Error('File type not supported');
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"build": "tsc",
"test": "jest",
"lint": "eslint .",
"lint:fix": "eslint --fix .",
"lint:file": "eslint"
},
"repository": {
Expand Down

0 comments on commit 605eede

Please sign in to comment.