stuff
This commit is contained in:
22
buildfiles/node_modules/isbinaryfile/LICENSE.txt
generated
vendored
Normal file
22
buildfiles/node_modules/isbinaryfile/LICENSE.txt
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
Copyright (c) 2019 Garen J. Torikian
|
||||
|
||||
MIT License
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
70
buildfiles/node_modules/isbinaryfile/README.md
generated
vendored
Normal file
70
buildfiles/node_modules/isbinaryfile/README.md
generated
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
# isBinaryFile
|
||||
|
||||
Detects if a file is binary in Node.js using ✨promises✨. Similar to [Perl's `-B` switch](http://stackoverflow.com/questions/899206/how-does-perl-know-a-file-is-binary), in that:
|
||||
- it reads the first few thousand bytes of a file
|
||||
- checks for a `null` byte; if it's found, it's binary
|
||||
- flags non-ASCII characters. After a certain number of "weird" characters, the file is flagged as binary
|
||||
|
||||
Much of the logic is pretty much ported from [ag](https://github.com/ggreer/the_silver_searcher).
|
||||
|
||||
Note: if the file doesn't exist or is a directory, an error is thrown.
|
||||
|
||||
## Installation
|
||||
|
||||
```
|
||||
npm install isbinaryfile
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
Returns `Promise<boolean>` (or just `boolean` for `*Sync`). `true` if the file is binary, `false` otherwise.
|
||||
|
||||
### isBinaryFile(filepath)
|
||||
|
||||
* `filepath` - a `string` indicating the path to the file.
|
||||
|
||||
### isBinaryFile(bytes[, size])
|
||||
|
||||
* `bytes` - a `Buffer` of the file's contents.
|
||||
* `size` - an optional `number` indicating the file size.
|
||||
|
||||
### isBinaryFileSync(filepath)
|
||||
|
||||
* `filepath` - a `string` indicating the path to the file.
|
||||
|
||||
|
||||
### isBinaryFileSync(bytes[, size])
|
||||
|
||||
* `bytes` - a `Buffer` of the file's contents.
|
||||
* `size` - an optional `number` indicating the file size.
|
||||
|
||||
### Examples
|
||||
|
||||
Here's an arbitrary usage:
|
||||
|
||||
```javascript
|
||||
const isBinaryFile = require("isbinaryfile").isBinaryFile;
|
||||
const fs = require("fs");
|
||||
|
||||
const filename = "fixtures/pdf.pdf";
|
||||
const data = fs.readFileSync(filename);
|
||||
const stat = fs.lstatSync(filename);
|
||||
|
||||
isBinaryFile(data, stat.size).then((result) => {
|
||||
if (result) {
|
||||
console.log("It is binary!")
|
||||
}
|
||||
else {
|
||||
console.log("No it is not.")
|
||||
}
|
||||
});
|
||||
|
||||
const isBinaryFileSync = require("isbinaryfile").isBinaryFileSync;
|
||||
const bytes = fs.readFileSync(filename);
|
||||
const size = fs.lstatSync(filename).size;
|
||||
console.log(isBinaryFileSync(bytes, size)); // true or false
|
||||
```
|
||||
|
||||
## Testing
|
||||
|
||||
Run `npm install`, then run `npm test`.
|
3
buildfiles/node_modules/isbinaryfile/lib/index.d.ts
generated
vendored
Normal file
3
buildfiles/node_modules/isbinaryfile/lib/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
/// <reference types="node" />
|
||||
export declare function isBinaryFile(file: string | Buffer, size?: number): Promise<boolean>;
|
||||
export declare function isBinaryFileSync(file: string | Buffer, size?: number): boolean;
|
152
buildfiles/node_modules/isbinaryfile/lib/index.js
generated
vendored
Normal file
152
buildfiles/node_modules/isbinaryfile/lib/index.js
generated
vendored
Normal file
@@ -0,0 +1,152 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const fs = require("fs");
|
||||
const util_1 = require("util");
|
||||
const statAsync = util_1.promisify(fs.stat);
|
||||
const openAsync = util_1.promisify(fs.open);
|
||||
const closeAsync = util_1.promisify(fs.close);
|
||||
const MAX_BYTES = 512;
|
||||
function isBinaryFile(file, size) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
if (isString(file)) {
|
||||
const stat = yield statAsync(file);
|
||||
isStatFile(stat);
|
||||
const fileDescriptor = yield openAsync(file, 'r');
|
||||
const allocBuffer = Buffer.alloc(MAX_BYTES);
|
||||
// Read the file with no encoding for raw buffer access.
|
||||
// NB: something is severely wrong with promisify, had to construct my own Promise
|
||||
return new Promise((fulfill, reject) => {
|
||||
fs.read(fileDescriptor, allocBuffer, 0, MAX_BYTES, 0, (err, bytesRead, _) => {
|
||||
closeAsync(fileDescriptor);
|
||||
if (err) {
|
||||
reject(err);
|
||||
}
|
||||
else {
|
||||
fulfill(isBinaryCheck(allocBuffer, bytesRead));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
else {
|
||||
if (size === undefined) {
|
||||
size = file.length;
|
||||
}
|
||||
return isBinaryCheck(file, size);
|
||||
}
|
||||
});
|
||||
}
|
||||
exports.isBinaryFile = isBinaryFile;
|
||||
function isBinaryFileSync(file, size) {
|
||||
if (isString(file)) {
|
||||
const stat = fs.statSync(file);
|
||||
isStatFile(stat);
|
||||
const fileDescriptor = fs.openSync(file, 'r');
|
||||
const allocBuffer = Buffer.alloc(MAX_BYTES);
|
||||
const bytesRead = fs.readSync(fileDescriptor, allocBuffer, 0, MAX_BYTES, 0);
|
||||
fs.closeSync(fileDescriptor);
|
||||
return isBinaryCheck(allocBuffer, bytesRead);
|
||||
}
|
||||
else {
|
||||
if (size === undefined) {
|
||||
size = file.length;
|
||||
}
|
||||
return isBinaryCheck(file, size);
|
||||
}
|
||||
}
|
||||
exports.isBinaryFileSync = isBinaryFileSync;
|
||||
function isBinaryCheck(fileBuffer, bytesRead) {
|
||||
// empty file. no clue what it is.
|
||||
if (bytesRead === 0) {
|
||||
return false;
|
||||
}
|
||||
let suspiciousBytes = 0;
|
||||
const totalBytes = Math.min(bytesRead, MAX_BYTES);
|
||||
// UTF-8 BOM
|
||||
if (bytesRead >= 3 && fileBuffer[0] === 0xef && fileBuffer[1] === 0xbb && fileBuffer[2] === 0xbf) {
|
||||
return false;
|
||||
}
|
||||
// UTF-32 BOM
|
||||
if (bytesRead >= 4 &&
|
||||
fileBuffer[0] === 0x00 &&
|
||||
fileBuffer[1] === 0x00 &&
|
||||
fileBuffer[2] === 0xfe &&
|
||||
fileBuffer[3] === 0xff) {
|
||||
return false;
|
||||
}
|
||||
// UTF-32 LE BOM
|
||||
if (bytesRead >= 4 &&
|
||||
fileBuffer[0] === 0xff &&
|
||||
fileBuffer[1] === 0xfe &&
|
||||
fileBuffer[2] === 0x00 &&
|
||||
fileBuffer[3] === 0x00) {
|
||||
return false;
|
||||
}
|
||||
// GB BOM
|
||||
if (bytesRead >= 4 &&
|
||||
fileBuffer[0] === 0x84 &&
|
||||
fileBuffer[1] === 0x31 &&
|
||||
fileBuffer[2] === 0x95 &&
|
||||
fileBuffer[3] === 0x33) {
|
||||
return false;
|
||||
}
|
||||
if (totalBytes >= 5 && fileBuffer.slice(0, 5).toString() === '%PDF-') {
|
||||
/* PDF. This is binary. */
|
||||
return true;
|
||||
}
|
||||
// UTF-16 BE BOM
|
||||
if (bytesRead >= 2 && fileBuffer[0] === 0xfe && fileBuffer[1] === 0xff) {
|
||||
return false;
|
||||
}
|
||||
// UTF-16 LE BOM
|
||||
if (bytesRead >= 2 && fileBuffer[0] === 0xff && fileBuffer[1] === 0xfe) {
|
||||
return false;
|
||||
}
|
||||
for (let i = 0; i < totalBytes; i++) {
|
||||
if (fileBuffer[i] === 0) {
|
||||
// NULL byte--it's binary!
|
||||
return true;
|
||||
}
|
||||
else if ((fileBuffer[i] < 7 || fileBuffer[i] > 14) && (fileBuffer[i] < 32 || fileBuffer[i] > 127)) {
|
||||
// UTF-8 detection
|
||||
if (fileBuffer[i] > 193 && fileBuffer[i] < 224 && i + 1 < totalBytes) {
|
||||
i++;
|
||||
if (fileBuffer[i] > 127 && fileBuffer[i] < 192) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else if (fileBuffer[i] > 223 && fileBuffer[i] < 240 && i + 2 < totalBytes) {
|
||||
i++;
|
||||
if (fileBuffer[i] > 127 && fileBuffer[i] < 192 && fileBuffer[i + 1] > 127 && fileBuffer[i + 1] < 192) {
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
suspiciousBytes++;
|
||||
// Read at least 32 fileBuffer before making a decision
|
||||
if (i > 32 && (suspiciousBytes * 100) / totalBytes > 10) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ((suspiciousBytes * 100) / totalBytes > 10) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
function isString(x) {
|
||||
return typeof x === 'string';
|
||||
}
|
||||
function isStatFile(stat) {
|
||||
if (!stat.isFile()) {
|
||||
throw new Error(`Path provided was not a file!`);
|
||||
}
|
||||
}
|
94
buildfiles/node_modules/isbinaryfile/package.json
generated
vendored
Normal file
94
buildfiles/node_modules/isbinaryfile/package.json
generated
vendored
Normal file
@@ -0,0 +1,94 @@
|
||||
{
|
||||
"_from": "isbinaryfile@^4.0.6",
|
||||
"_id": "isbinaryfile@4.0.6",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-ORrEy+SNVqUhrCaal4hA4fBzhggQQ+BaLntyPOdoEiwlKZW9BZiJXjg3RMiruE4tPEI3pyVPpySHQF/dKWperg==",
|
||||
"_location": "/isbinaryfile",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "isbinaryfile@^4.0.6",
|
||||
"name": "isbinaryfile",
|
||||
"escapedName": "isbinaryfile",
|
||||
"rawSpec": "^4.0.6",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^4.0.6"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/app-builder-lib"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/isbinaryfile/-/isbinaryfile-4.0.6.tgz",
|
||||
"_shasum": "edcb62b224e2b4710830b67498c8e4e5a4d2610b",
|
||||
"_spec": "isbinaryfile@^4.0.6",
|
||||
"_where": "/home/shihaam/www/freezer.shihaam.me/node_modules/app-builder-lib",
|
||||
"bugs": {
|
||||
"url": "https://github.com/gjtorikian/isBinaryFile/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {},
|
||||
"deprecated": false,
|
||||
"description": "Detects if a file is binary in Node.js. Similar to Perl's -B.",
|
||||
"devDependencies": {
|
||||
"@types/jest": "^23.3.14",
|
||||
"@types/node": "^10.17.17",
|
||||
"jest": "^25.1.0",
|
||||
"prettier": "^1.19.1",
|
||||
"release-it": "^12.6.3",
|
||||
"ts-jest": "^23.10.5",
|
||||
"tslint": "^5.20.1",
|
||||
"tslint-config-prettier": "^1.18.0",
|
||||
"typescript": "^3.8.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 8.0.0"
|
||||
},
|
||||
"files": [
|
||||
"lib/**/*"
|
||||
],
|
||||
"funding": "https://github.com/sponsors/gjtorikian/",
|
||||
"homepage": "https://github.com/gjtorikian/isBinaryFile#readme",
|
||||
"keywords": [
|
||||
"text",
|
||||
"binary",
|
||||
"encoding",
|
||||
"istext",
|
||||
"is text",
|
||||
"isbinary",
|
||||
"is binary",
|
||||
"is text or binary",
|
||||
"is text or binary file",
|
||||
"isbinaryfile",
|
||||
"is binary file",
|
||||
"istextfile",
|
||||
"is text file"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "lib/index.js",
|
||||
"maintainers": [
|
||||
{
|
||||
"name": "Garen J. Torikian",
|
||||
"email": "gjtorikian@gmail.com"
|
||||
}
|
||||
],
|
||||
"name": "isbinaryfile",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/gjtorikian/isBinaryFile.git"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\"",
|
||||
"lint": "tslint -p tsconfig.json",
|
||||
"postversion": "git push && git push --tags",
|
||||
"prepare": "npm run build",
|
||||
"prepublishOnly": "npm test && npm run lint",
|
||||
"preversion": "npm run lint",
|
||||
"release": "release-it",
|
||||
"test": "jest --config jestconfig.json",
|
||||
"version": "npm run format && git add -A src",
|
||||
"watch": "tsc -w"
|
||||
},
|
||||
"types": "lib/index.d.ts",
|
||||
"version": "4.0.6"
|
||||
}
|
Reference in New Issue
Block a user