mirror of
https://github.com/ThatGuySam/doesitarm.git
synced 2026-05-18 06:44:46 -07:00
Enable passing custom FileApi
This commit is contained in:
parent
23951fd84c
commit
d18339f4d6
1 changed files with 20 additions and 7 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
//macho.js
|
// macho.js
|
||||||
//Written by Sem Voigtländer
|
// Written by Sem Voigtländer, modified by Sam Carlton
|
||||||
//Licensed under the MIT License
|
// Licensed under the MIT License
|
||||||
|
|
||||||
import { mime_binary } from './mimetypes.js'
|
import { mime_binary } from './mimetypes.js'
|
||||||
import { ReadUint32, ReadUint16LE, ReadUint32LE, ReadUint16 } from './memory.js'
|
import { ReadUint32, ReadUint16LE, ReadUint32LE, ReadUint16 } from './memory.js'
|
||||||
|
|
@ -14,6 +14,8 @@ import { FILE_FLAGS, FILE_TYPE } from './macho.file.js'
|
||||||
import Cstr from './macho.cstr.js'
|
import Cstr from './macho.cstr.js'
|
||||||
import { SegmentCommand } from './macho.segment.js'
|
import { SegmentCommand } from './macho.segment.js'
|
||||||
|
|
||||||
|
let FileApi = undefined
|
||||||
|
|
||||||
function default_callback(buffer) {
|
function default_callback(buffer) {
|
||||||
console.log('Received ' + buffer.byteLength / (1024 * 1024) + ' MB');
|
console.log('Received ' + buffer.byteLength / (1024 * 1024) + ' MB');
|
||||||
}
|
}
|
||||||
|
|
@ -69,8 +71,10 @@ export function MachoParser(file, callback) {
|
||||||
|
|
||||||
const machoOutputData = {}
|
const machoOutputData = {}
|
||||||
|
|
||||||
|
const hasFileReader = typeof FileReader !== 'undefined'
|
||||||
|
|
||||||
//properties
|
//properties
|
||||||
this.reader = new FileReader();
|
this.reader = hasFileReader ? new FileReader() : new FileApi.FileReader()
|
||||||
|
|
||||||
function writeToCallback(val) {
|
function writeToCallback(val) {
|
||||||
return
|
return
|
||||||
|
|
@ -151,7 +155,9 @@ export function MachoParser(file, callback) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.reader.onloadend = function(e) {
|
const onloadend = function (e) {
|
||||||
|
|
||||||
|
// console.log( 'Load complete', e )
|
||||||
|
|
||||||
let fileType = mime_binary;
|
let fileType = mime_binary;
|
||||||
|
|
||||||
|
|
@ -298,7 +304,11 @@ export function MachoParser(file, callback) {
|
||||||
}).catch(console.log.bind(console));
|
}).catch(console.log.bind(console));
|
||||||
};
|
};
|
||||||
|
|
||||||
this.reader.readAsArrayBuffer(file);
|
// console.log( 'this.reader', this.reader )
|
||||||
|
|
||||||
|
this.reader.addEventListener( 'load', onloadend )
|
||||||
|
|
||||||
|
this.reader.readAsArrayBuffer( file )
|
||||||
|
|
||||||
// console.log('Parsing, please wait...');
|
// console.log('Parsing, please wait...');
|
||||||
|
|
||||||
|
|
@ -306,7 +316,10 @@ export function MachoParser(file, callback) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export default async function ( file ) {
|
export default async function ( file, fileApi ) {
|
||||||
|
|
||||||
|
FileApi = fileApi
|
||||||
|
|
||||||
return new Promise( ( resolve, reject ) => {
|
return new Promise( ( resolve, reject ) => {
|
||||||
try {
|
try {
|
||||||
(new MachoParser( file, resolve ))
|
(new MachoParser( file, resolve ))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue