-
Notifications
You must be signed in to change notification settings - Fork 301
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #271 from NASA-AMMOS/magic-bytes
Use magic bytes to determine file type when parsing
- Loading branch information
Showing
6 changed files
with
43 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
export function readMagicBytes( bufferOrDataView ) { | ||
|
||
let view; | ||
if ( bufferOrDataView instanceof DataView ) { | ||
|
||
view = bufferOrDataView; | ||
|
||
} else { | ||
|
||
view = new DataView( bufferOrDataView ); | ||
|
||
} | ||
|
||
if ( String.fromCharCode( view.getUint8( 0 ) ) === '{' ) { | ||
|
||
return null; | ||
|
||
} | ||
|
||
let magicBytes = ''; | ||
for ( let i = 0; i < 4; i ++ ) { | ||
|
||
magicBytes += String.fromCharCode( view.getUint8( i ) ); | ||
|
||
} | ||
|
||
return magicBytes; | ||
|
||
} |