Skip to content

Commit

Permalink
Added a string conversion function.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sjoerd Tieleman committed Mar 26, 2015
1 parent 84a6a10 commit ba11687
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## codem-isoboxer 0.0.3 (2015/03/26) ##

* Added a simple utility function to convert a DataView to a string (ISOBoxer.Utils.dataViewToString)

## codem-isoboxer 0.0.2 (2015/03/26) ##

* Added `fetch` and `fetchAll` functions to ISOFile
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ structure yourself:

Traversal of the box structure is always depth first.

An additional utility method is included to convert DataViews into strings (completely naïve, no fancy encoding support):

var parsedFile = ISOBoxer.create(arrayBuffer); // Parse the file
var mdat = parsedFile.fetch('mdat'); // Get the first 'mdat' box
var text = ISOBoxer.Utils.dataViewToString(mdat.data); // Convert the data into a string (e.g. captions)

### NodeJS

Does it work in NodeJS? Well, it's mostly meant to be run in a web browser, but since Node supports most features it shouldn't be
Expand Down
14 changes: 13 additions & 1 deletion dist/iso_boxer.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,19 @@ ISOBoxer.create = function(arrayBuffer) {
return new ISOFile(arrayBuffer).parse();
};

if (typeof exports !== 'undefined') exports.create = ISOBoxer.create;;
ISOBoxer.Utils = {};
ISOBoxer.Utils.dataViewToString = function(dataView) {
var str = '';
for (var i=0; i<dataView.byteLength; i++) {
str += String.fromCharCode(dataView.getUint8(i));
}
return str;
};

if (typeof exports !== 'undefined') {
exports.create = ISOBoxer.create;
exports.Utils = ISOBoxer.Utils;
};
var ISOFile = function(arrayBuffer) {
this._raw = new DataView(arrayBuffer);
this._cursor = new ISOBoxer.Cursor();
Expand Down
2 changes: 1 addition & 1 deletion dist/iso_boxer.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "codem-isoboxer",
"version": "0.0.2",
"version": "0.0.3",
"description": "Browser-based MPEG-4 (ISOBMFF) file/box parsing.",
"keywords": [
"mp4", "mpeg-4", "mpeg4", "isobmff", "parser"
Expand Down
14 changes: 13 additions & 1 deletion src/iso_boxer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,16 @@ ISOBoxer.create = function(arrayBuffer) {
return new ISOFile(arrayBuffer).parse();
};

if (typeof exports !== 'undefined') exports.create = ISOBoxer.create;
ISOBoxer.Utils = {};
ISOBoxer.Utils.dataViewToString = function(dataView) {
var str = '';
for (var i=0; i<dataView.byteLength; i++) {
str += String.fromCharCode(dataView.getUint8(i));
}
return str;
};

if (typeof exports !== 'undefined') {
exports.create = ISOBoxer.create;
exports.Utils = ISOBoxer.Utils;
}

0 comments on commit ba11687

Please sign in to comment.