@@ -2,24 +2,24 @@ import AbstractInput from "./AbstractInput";
22import BufferInput from "./BufferInput" ;
33import FolderInput from "./FolderInput" ;
44import fs from "fs-extra" ;
5+ import isBuffer from "./../Output/isBuffer" ;
56import MetadataConverter from "../Converter/MetadataConverter" ;
67import path from "path" ;
7- import ZipInput from "./ZipInput" ;
88
99/**
10- * @param {string|Buffer|Array } input
10+ * @param {string|Buffer|ArrayBuffer|Uint8Array| Array } input
1111 *
1212 * @returns {Promise<AbstractInput> }
1313 *
1414 * @throws {Error }
1515 */
1616async function detectInput ( input ) {
17- if ( Buffer . isBuffer ( input ) ) {
17+ if ( isBuffer ( input ) ) {
1818 return new BufferInput ( input ) ;
1919 }
2020
2121 if ( Array . isArray ( input ) ) {
22- if ( Buffer . isBuffer ( input [ 0 ] ) ) {
22+ if ( isBuffer ( input [ 0 ] ) ) {
2323 return new BufferInput ( input [ 0 ] , input [ 1 ] ) ;
2424 }
2525
@@ -30,6 +30,10 @@ async function detectInput(input) {
3030 throw new Error ( `Invalid string input!` ) ;
3131 }
3232
33+ if ( ! fs ) {
34+ throw new Error ( `Browser only supports Buffer input!` ) ;
35+ }
36+
3337 if ( ! fs . existsSync ( input ) ) {
3438 throw new Error ( `The input ${ input } does not exists!` ) ;
3539 }
@@ -39,15 +43,15 @@ async function detectInput(input) {
3943 throw new Error ( `Invalid folder input ${ input } - Missing ${ MetadataConverter . PACK_MCMETA } !` ) ;
4044 }
4145
42- return new FolderInput ( input ) ;
46+ return new FolderInput ( input , input ) ;
4347 }
4448
4549
4650 const ext = path . extname ( input ) . toLowerCase ( ) . substr ( 1 ) ;
4751
4852 switch ( ext ) {
4953 case "zip" :
50- return new ZipInput ( input ) ;
54+ return new BufferInput ( await fs . readFile ( input ) , input ) ;
5155
5256 default :
5357 throw new Error ( `The input ${ input } is no zip archive or folder!` ) ;
0 commit comments