mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-21 07:16:17 -04:00
WIP HAD to move NodeDish out - NONE of it is async!
This commit is contained in:
parent
aafde8986d
commit
04b7f2fa8c
16 changed files with 442 additions and 411 deletions
41
src/node/File.mjs
Normal file
41
src/node/File.mjs
Normal file
|
@ -0,0 +1,41 @@
|
|||
/**
|
||||
* @author d98762625 [d98762625@gmail.com]
|
||||
* @copyright Crown Copyright 2019
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import mime from "mime";
|
||||
|
||||
/**
|
||||
* FileShim
|
||||
*
|
||||
* Create a class that behaves like the File object in the Browser so that
|
||||
* operations that use the File object still work.
|
||||
*
|
||||
* File doesn't write to disk, but it would be easy to do so with e.gfs.writeFile.
|
||||
*/
|
||||
class File {
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param {String|Array|ArrayBuffer|Buffer} bits - file content
|
||||
* @param {String} name (optional) - file name
|
||||
* @param {Object} stats (optional) - file stats e.g. lastModified
|
||||
*/
|
||||
constructor(data, name="", stats={}) {
|
||||
this.data = Buffer.from(data);
|
||||
this.name = name;
|
||||
this.lastModified = stats.lastModified || Date.now();
|
||||
this.type = stats.type || mime.getType(this.name);
|
||||
}
|
||||
|
||||
/**
|
||||
* size property
|
||||
*/
|
||||
get size() {
|
||||
return this.data.length;
|
||||
}
|
||||
}
|
||||
|
||||
export default File;
|
Loading…
Add table
Add a link
Reference in a new issue