Skip to content

Commit

Permalink
Merge pull request #26 from runk/revert-25-master
Browse files Browse the repository at this point in the history
Revert "Compatilibilty for web and react-native"
  • Loading branch information
Dmitry Shirokov authored Mar 30, 2020
2 parents 1b192fb + 6536ece commit c06f4dc
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 55 deletions.
2 changes: 1 addition & 1 deletion encoding/iso2022.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var util = require('../util'),
var util = require('util'),
Match = require ('../match');


Expand Down
2 changes: 1 addition & 1 deletion encoding/mbcs.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var util = require('../util'),
var util = require('util'),
Match = require ('../match');

/**
Expand Down
2 changes: 1 addition & 1 deletion encoding/sbcs.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var util = require('../util'),
var util = require('util'),
Match = require ('../match');

/**
Expand Down
2 changes: 1 addition & 1 deletion encoding/unicode.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
var util = require('../util'),
var util = require('util'),
Match = require ('../match');

/**
Expand Down
46 changes: 0 additions & 46 deletions fs.js

This file was deleted.

46 changes: 46 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@

var fs = require('fs');

var utf8 = require('./encoding/utf8'),
unicode = require('./encoding/unicode'),
mbcs = require('./encoding/mbcs'),
Expand Down Expand Up @@ -75,6 +78,49 @@ module.exports.detect = function(buffer, opts) {
}
};

module.exports.detectFile = function(filepath, opts, cb) {
if (typeof opts === 'function') {
cb = opts;
opts = undefined;
}

var fd;

var handler = function(err, buffer) {
if (fd) {
fs.closeSync(fd);
}

if (err) return cb(err, null);
cb(null, self.detect(buffer, opts));
};

if (opts && opts.sampleSize) {
fd = fs.openSync(filepath, 'r'),
sample = Buffer.allocUnsafe(opts.sampleSize);

fs.read(fd, sample, 0, opts.sampleSize, null, function(err) {
handler(err, sample);
});
return;
}

fs.readFile(filepath, handler);
};

module.exports.detectFileSync = function(filepath, opts) {
if (opts && opts.sampleSize) {
var fd = fs.openSync(filepath, 'r'),
sample = Buffer.allocUnsafe(opts.sampleSize);

fs.readSync(fd, sample, 0, opts.sampleSize);
fs.closeSync(fd);
return self.detect(sample, opts);
}

return self.detect(fs.readFileSync(filepath), opts);
};

// Wrappers for the previous functions to return all encodings
module.exports.detectAll = function(buffer, opts) {
if (typeof opts !== 'object') {
Expand Down
5 changes: 0 additions & 5 deletions util.js

This file was deleted.

0 comments on commit c06f4dc

Please sign in to comment.