Merge pull request #26 from runk/revert-25-master

Revert "Compatilibilty for web and react-native"
This commit is contained in:
Dmitry Shirokov 2020-03-30 14:32:07 +11:00 committed by GitHub
commit c06f4dce7e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 50 additions and 55 deletions

View File

@ -1,4 +1,4 @@
var util = require('../util'),
var util = require('util'),
Match = require ('../match');

View File

@ -1,4 +1,4 @@
var util = require('../util'),
var util = require('util'),
Match = require ('../match');
/**

View File

@ -1,4 +1,4 @@
var util = require('../util'),
var util = require('util'),
Match = require ('../match');
/**

View File

@ -1,5 +1,5 @@
'use strict';
var util = require('../util'),
var util = require('util'),
Match = require ('../match');
/**

46
fs.js
View File

@ -1,46 +0,0 @@
var fs = require('fs');
var self = require('./index');
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);
};

View File

@ -1,3 +1,6 @@
var fs = require('fs');
var utf8 = require('./encoding/utf8'),
unicode = require('./encoding/unicode'),
mbcs = require('./encoding/mbcs'),
@ -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') {

View File

@ -1,5 +0,0 @@
module.exports.inherits = function(a, b) {
for (var key of Object.keys(b.prototype)) {
a.prototype[key] = b.prototype[key];
}
}