-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Bluebird Removal): Migrate detect function to native promises (#86)
- Loading branch information
1 parent
ab790e6
commit 605eede
Showing
2 changed files
with
11 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters