Skip to content

Commit 04d5971

Browse files
author
ozelot379
committed
Readd missing files
1 parent 9e4a785 commit 04d5971

11 files changed

Lines changed: 599 additions & 2 deletions

File tree

‎.gitignore‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.idea
22
dist
3-
input
3+
/input
44
node_modules
5-
output
5+
/output

‎src/input/AbstractInput.js‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* Class AbstractInput
3+
*
4+
* @abstract
5+
*/
6+
class AbstractInput {
7+
/**
8+
* AbstractInput constructor
9+
*
10+
* @param {string|Buffer|ArrayBuffer|Uint8Array} input
11+
* @param {string} filename
12+
*
13+
* @throws {Error}
14+
*/
15+
constructor(input, filename) {
16+
if (this.constructor === AbstractInput) {
17+
throw new Error("Can't instantiate abstract class!");
18+
}
19+
20+
/**
21+
* @type {string|Buffer|ArrayBuffer|Uint8Array}
22+
*
23+
* @protected
24+
*/
25+
this.input = input;
26+
/**
27+
* @type {string}
28+
*
29+
* @protected
30+
*/
31+
this.filename = filename;
32+
}
33+
}
34+
35+
export default AbstractInput;

‎src/input/BufferInput.js‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import AbstractInput from "./AbstractInput";
2+
3+
/**
4+
* Class BufferInput
5+
*/
6+
class BufferInput extends AbstractInput {
7+
8+
}
9+
10+
export default BufferInput;

‎src/input/FolderInput.js‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import AbstractInput from "./AbstractInput";
2+
3+
/**
4+
* Class FolderInput
5+
*/
6+
class FolderInput extends AbstractInput {
7+
8+
}
9+
10+
export default FolderInput;

‎src/input/index.js‎

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import AbstractInput from "./AbstractInput";
2+
import BufferInput from "./BufferInput";
3+
import FolderInput from "./FolderInput";
4+
import fs from "fs-extra";
5+
import isBuffer from "./../output/isBuffer";
6+
import MetadataConverter from "../converter/MetadataConverter";
7+
import path from "path";
8+
9+
/**
10+
* @param {string|Buffer|ArrayBuffer|Uint8Array|Array} input
11+
*
12+
* @returns {Promise<AbstractInput>}
13+
*
14+
* @throws {Error}
15+
*/
16+
async function detectInput(input) {
17+
if (isBuffer(input)) {
18+
return new BufferInput(input);
19+
}
20+
21+
if (Array.isArray(input)) {
22+
if (isBuffer(input[0])) {
23+
return new BufferInput(input[0], input[1]);
24+
}
25+
26+
throw new Error(`Invalid array input!`);
27+
}
28+
29+
if (typeof input !== "string") {
30+
throw new Error(`Invalid string input!`);
31+
}
32+
33+
if (!fs) {
34+
throw new Error(`Browser only supports Buffer input!`);
35+
}
36+
37+
if (!fs.existsSync(input)) {
38+
throw new Error(`The input ${input} does not exists!`);
39+
}
40+
41+
if (fs.statSync(input).isDirectory()) {
42+
if (!fs.existsSync(path.join(input, MetadataConverter.PACK_MCMETA))) { // Prevents copy whole wrong folders
43+
throw new Error(`Invalid folder input ${input} - Missing ${MetadataConverter.PACK_MCMETA}!`);
44+
}
45+
46+
return new FolderInput(input, input);
47+
}
48+
49+
50+
const ext = path.extname(input).toLowerCase().substr(1);
51+
52+
switch (ext) {
53+
case "zip":
54+
return new BufferInput(await fs.readFile(input), input);
55+
56+
default:
57+
throw new Error(`The input ${input} is no zip archive or folder!`);
58+
}
59+
}
60+
61+
export default detectInput;

‎src/output/AbstractOutput.js‎

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
import AbstractInput from "../input/AbstractInput";
2+
import Log from "../log/Log";
3+
4+
/**
5+
* Class AbstractOutput
6+
*
7+
* @abstract
8+
*/
9+
class AbstractOutput {
10+
/**
11+
* AbstractOutput constructor
12+
*
13+
* @param {string|Buffer|ArrayBuffer|Uint8Array} output
14+
* @param {AbstractInput} input
15+
* @param {Log} log
16+
*
17+
* @throws {Error}
18+
*/
19+
constructor(output, input, log) {
20+
if (this.constructor === AbstractOutput) {
21+
throw new Error("Can't instantiate abstract class!");
22+
}
23+
24+
/**
25+
* @type {string|Buffer|ArrayBuffer|Uint8Array}
26+
*
27+
* @protected
28+
*/
29+
this.output = output;
30+
/**
31+
* @type {AbstractInput}
32+
*
33+
* @protected
34+
*/
35+
this.input = input;
36+
/**
37+
* @type {Log}
38+
*
39+
* @protected
40+
*/
41+
this.log = log;
42+
}
43+
44+
/**
45+
* @returns {Promise<>}
46+
*
47+
* @throws {Error}
48+
*
49+
* @abstract
50+
*/
51+
async init() {
52+
53+
}
54+
55+
/**
56+
* @returns {Promise<string|Buffer|ArrayBuffer|Uint8Array>}
57+
*
58+
* @throws {Error}
59+
*
60+
* @abstract
61+
*/
62+
async generate() {
63+
64+
}
65+
66+
/**
67+
* @param {string} path
68+
*
69+
* @returns {Promise<boolean>}
70+
*
71+
* @throws {Error}
72+
*
73+
* @abstract
74+
*/
75+
async exists(path) {
76+
77+
}
78+
79+
/**
80+
* @param {string} from
81+
* @param {string} to
82+
*
83+
* @returns {Promise<>}
84+
*
85+
* @throws {Error}
86+
*
87+
* @abstract
88+
*/
89+
async rename(from, to) {
90+
91+
}
92+
93+
/**
94+
* @param {string} file
95+
*
96+
* @returns {Promise<Buffer>}
97+
*
98+
* @throws {Error}
99+
*
100+
* @abstract
101+
*/
102+
async read(file) {
103+
104+
}
105+
106+
/**
107+
* @param {string} file
108+
* @param {Buffer} data
109+
*
110+
* @returns {Promise<>}
111+
*
112+
* @throws {Error}
113+
*
114+
* @abstract
115+
*/
116+
async write(file, data) {
117+
118+
}
119+
120+
/**
121+
* @param {string} path
122+
*
123+
* @returns {Promise<>}
124+
*
125+
* @throws {Error}
126+
*
127+
* @abstract
128+
*/
129+
async delete(path) {
130+
131+
}
132+
133+
/**
134+
* @param {string} from
135+
* @param {string} to
136+
*
137+
* @returns {Promise<>}
138+
*
139+
* @throws {Error}
140+
*
141+
* @abstract
142+
*/
143+
async copy(from, to) {
144+
145+
}
146+
}
147+
148+
export default AbstractOutput;

‎src/output/BufferOutput.js‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import ZipOutput from "./ZipOutput";
2+
3+
/**
4+
* Class BufferOutput
5+
*/
6+
class BufferOutput extends ZipOutput {
7+
/**
8+
* @inheritDoc
9+
*/
10+
async generate() {
11+
this.log.log(`Pack output`);
12+
13+
return this.generateZip(Buffer.isBuffer(this.output) ? undefined : this.output.constructor.name.toLowerCase());
14+
}
15+
}
16+
17+
export default BufferOutput;

0 commit comments

Comments
 (0)