Skip to content

Commit

Permalink
2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
legokichi committed Aug 17, 2017
1 parent d80123f commit 09fceb1
Show file tree
Hide file tree
Showing 20 changed files with 95 additions and 91 deletions.
2 changes: 1 addition & 1 deletion lib/EBML.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export interface DateElement extends ChildElementValue {
* Date - signed 8 octets integer in nanoseconds with 0 indicating the precise
* beginning of the millennium (at 2001-01-01T00:00:00,000000000 UTC)
*/
value: string;
value: Date;
}
export interface ElementDetail {
schema: Schema;
Expand Down
17 changes: 8 additions & 9 deletions lib/EBMLDecoder.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tools_1 = require("./tools");
var int64_buffer_1 = require("int64-buffer");
var tools = require("./tools");
var Buffer = require("buffer/").Buffer;
var byEbmlID = require("matroska/lib/schema").byEbmlID;
var readVint = require("ebml/lib/ebml/tools").readVint;
var ebmlBlock = require("ebml-block");
var schema = require("matroska/lib/schema");
var byEbmlID = schema.byEbmlID;
// https://www.matroska.org/technical/specs/index.html
var State;
(function (State) {
Expand All @@ -15,7 +14,7 @@ var State;
})(State || (State = {}));
var EBMLDecoder = (function () {
function EBMLDecoder() {
this._buffer = new Buffer(0);
this._buffer = new tools_1.Buffer(0);
this._tag_stack = [];
this._state = State.STATE_TAG;
this._cursor = 0;
Expand All @@ -31,7 +30,7 @@ var EBMLDecoder = (function () {
};
EBMLDecoder.prototype.readChunk = function (chunk) {
// 読みかけの(読めなかった) this._buffer と 新しい chunk を合わせて読み直す
this._buffer = tools.concat([this._buffer, new Buffer(chunk)]);
this._buffer = tools.concat([this._buffer, new tools_1.Buffer(chunk)]);
while (this._cursor < this._buffer.length) {
// console.log(this._cursor, this._total, this._tag_stack);
if (this._state === State.STATE_TAG && !this.readTag()) {
Expand Down Expand Up @@ -63,7 +62,7 @@ var EBMLDecoder = (function () {
return false;
}
// read ebml id vint without first byte
var tag = readVint(this._buffer, this._cursor);
var tag = tools_1.readVint(this._buffer, this._cursor);
// tag が読めなかった
if (tag == null) {
return false;
Expand Down Expand Up @@ -111,7 +110,7 @@ var EBMLDecoder = (function () {
return false;
}
// read ebml datasize vint without first byte
var size = readVint(this._buffer, this._cursor);
var size = tools_1.readVint(this._buffer, this._cursor);
// まだ読めない
if (size == null) {
return false;
Expand Down Expand Up @@ -199,7 +198,7 @@ var EBMLDecoder = (function () {
break;
// Binary - not interpreted by the parser
case "d":
tagObj.value = new int64_buffer_1.Int64BE(data).toString();
tagObj.value = tools_1.convertEBMLDateToJSDate(new int64_buffer_1.Int64BE(data).toNumber());
break;
}
if (tagObj.value === null) {
Expand Down
10 changes: 5 additions & 5 deletions lib/EBMLEncoder.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tools = require("./tools");
var Buffer = require("buffer/").Buffer;
var byEbmlID = require("matroska/lib/schema").byEbmlID;
var writeVint = require("ebml/lib/ebml/tools").writeVint;
var tools_1 = require("./tools");
var schema = require("matroska/lib/schema");
var byEbmlID = schema.byEbmlID;
var EBMLEncoder = (function () {
function EBMLEncoder() {
this._schema = byEbmlID;
Expand Down Expand Up @@ -40,7 +40,7 @@ var EBMLEncoder = (function () {
for (var i = 0; i < tagNums.length; i++) {
var tagNum = tagNums[i];
if (this._schema[tagNum].name === tagName) {
return new Buffer(tagNum.toString(16), 'hex');
return new tools_1.Buffer(tagNum.toString(16), 'hex');
}
}
return null;
Expand Down Expand Up @@ -79,7 +79,7 @@ var EBMLEncoder = (function () {
* 閉じタグ不定長の場合はスタックに積まずに即時バッファに書き込む
*/
if (elm.unknownSize) {
var data = tools.encodeTag(tagId, new Buffer(0), elm.unknownSize);
var data = tools.encodeTag(tagId, new tools_1.Buffer(0), elm.unknownSize);
this._buffers = this._buffers.concat(data);
return;
}
Expand Down
3 changes: 1 addition & 2 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var _1 = require("./");
var EBMLReader_1 = require("./EBMLReader");
var com = require("commander");
var fs = require("fs");
var version = require("../package.json").version;
Expand All @@ -19,7 +18,7 @@ if (args.length < 1) {
}
if (com.seekable) {
var decoder = new _1.Decoder();
var reader_1 = new EBMLReader_1.default();
var reader_1 = new _1.Reader();
reader_1.logging = false;
reader_1.drop_default_duration = false;
var buf = fs.readFileSync(args[0]);
Expand Down
3 changes: 2 additions & 1 deletion lib/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export * from "./EBML";
import Decoder from "./EBMLDecoder";
import Encoder from "./EBMLEncoder";
import Reader from "./EBMLReader";
import * as tools from "./tools";
declare const version: string;
export { version, Decoder, Encoder, tools };
export { version, Decoder, Encoder, Reader, tools };
3 changes: 2 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ var EBMLDecoder_1 = require("./EBMLDecoder");
exports.Decoder = EBMLDecoder_1.default;
var EBMLEncoder_1 = require("./EBMLEncoder");
exports.Encoder = EBMLEncoder_1.default;
//import Reader from "./EBMLReader";
var EBMLReader_1 = require("./EBMLReader");
exports.Reader = EBMLReader_1.default;
var tools = require("./tools");
exports.tools = tools;
var version = require("../package.json").version;
Expand Down
2 changes: 1 addition & 1 deletion lib/tools.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,4 @@ export declare function encodeValueToBuffer(elm: EBML.ChildElementsValue): EBML.
export declare function createUIntBuffer(value: number): Buffer;
export declare function createIntBuffer(value: number): Buffer;
export declare function createFloatBuffer(value: number, bytes?: 4 | 8): Buffer;
export declare function convertEBMLDateToJSDate(int64str: string | Date): Date;
export declare function convertEBMLDateToJSDate(int64str: number | string | Date): Date;
14 changes: 9 additions & 5 deletions lib/tools.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/// <reference types="node"/>
var int64_buffer_1 = require("int64-buffer");
var EBMLEncoder_1 = require("./EBMLEncoder");
exports.Buffer = require("buffer/").Buffer;
exports.readVint = require("ebml/lib/ebml/tools").readVint;
exports.writeVint = require("ebml/lib/ebml/tools").writeVint;
exports.ebmlBlock = require("ebml-block");
var _Buffer = require("buffer/");
var _tools = require("ebml/lib/ebml/tools");
var _block = require("ebml-block");
exports.Buffer = _Buffer.Buffer;
exports.readVint = _tools.readVint;
exports.writeVint = _tools.writeVint;
exports.ebmlBlock = _block;
function readBlock(buf) {
return exports.ebmlBlock(new exports.Buffer(buf));
}
Expand Down Expand Up @@ -627,7 +631,7 @@ function encodeValueToBuffer(elm) {
data = elm.value;
break;
case "d":
data = new int64_buffer_1.Int64BE(elm.value).toBuffer();
data = new int64_buffer_1.Int64BE(elm.value.getTime().toString()).toBuffer();
break;
}
return Object.assign({}, elm, { data: data });
Expand Down
17 changes: 7 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ts-ebml",
"version": "1.8.6",
"version": "2.0.0",
"description": "ebml decoder and encoder",
"scripts": {
"setup": "npm install -g http-server;",
Expand All @@ -9,12 +9,11 @@
"reset": "rm -rf node_modules",
"mkdir": "mkdir lib dist 2>/dev/null",
"clean": "rm -rf lib/* dist/* test/*.js; mkdir -p dist",
"build": "npm run clean && tsc -p .; npm run browserify; npm run reader",
"build": "npm run clean && tsc -p .; npm run browserify",
"start": "http-server . -s & tsc -w -p .& watchify lib/example_seekable.js -o test/example_seekable.js",
"stop": "killall -- node */tsc -w -p",
"browserify": "browserify lib/index.js --standalone EBML -o dist/EBML.js",
"watchify": "watchify lib/index.js --standalone EBML -o dist/EBMl.js -v",
"reader": "browserify lib/EBMLReader.js --standalone EBMLReader -o dist/EBMLReader.js",
"test": "tsc; espower lib/test.js > lib/test.tmp; mv -f lib/test.tmp lib/test.js; browserify lib/test.js -o test/test.js",
"example": "tsc; browserify lib/example_seekable.js -o test/example_seekable.js",
"examples": "tsc; for file in `find lib -name 'example_*.js' -type f -printf '%f\\n'`; do browserify lib/$file -o test/$file; done",
Expand All @@ -41,29 +40,27 @@
},
"homepage": "https://github.com/legokichi/ts-ebml#readme",
"dependencies": {
"buffer": "5.0.4",
"commander": "^2.9.0",
"ebml": "^2.2.0",
"buffer": "^5.0.7",
"commander": "^2.11.0",
"ebml": "^2.2.1",
"ebml-block": "^1.1.0",
"events": "^1.1.1",
"int64-buffer": "^0.1.9",
"matroska": "^2.2.3"
},
"devDependencies": {
"@types/commander": "^2.9.1",
"@types/node": "0.0.2",
"@types/power-assert-formatter": "^1.4.28",
"@types/qunit": "^2.0.31",
"browserify": "^13.1.0",
"empower": "^1.2.3",
"espower-cli": "^1.1.0",
"power-assert": "^1.4.4",
"power-assert-formatter": "^1.4.1",
"qunit-tap": "^1.5.1",
"qunitjs": "^2.0.1",
"qunitjs": "^2.4.0",
"tslint": "^3.15.1",
"typedoc": "^0.5.3",
"typescript": "^2.4.0",
"typescript": "^2.4.2",
"watchify": "^3.7.0"
},
"bin": "./lib/cli.js",
Expand Down
3 changes: 1 addition & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ type ChildElementBuffer = {
data: Buffer;
};
type ChildElementValue = ChildElementBuffer & {
value: number|string|Buffer;
value: number|string|Buffer|Date;
};
type ElementDetail = {
tagStart: number;
Expand All @@ -110,7 +110,6 @@ namespace tools {
export function readVint(buffer: Buffer, start: number): null | ({length: number; value: number; });
export function writeVint(val: number): Buffer;
export function readBlock(buf: ArrayBuffer): EBML.SimpleBlock;
export function convertEBMLDateToJSDate(int64str: string | Date): Date;
}
```

Expand Down
3 changes: 2 additions & 1 deletion src/EBML.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {Buffer} from "./tools";
export type ChildElementsValue = NumberElement | StringElement | BinaryElement | DateElement;
export type EBMLElementValue = MasterElement | ChildElementsValue;
export type ChildElementBuffer = ChildElement & {data: Buffer};
Expand Down Expand Up @@ -45,7 +46,7 @@ export interface DateElement extends ChildElementValue {
* Date - signed 8 octets integer in nanoseconds with 0 indicating the precise
* beginning of the millennium (at 2001-01-01T00:00:00,000000000 UTC)
*/
value: string;
value: Date;
}


Expand Down
10 changes: 4 additions & 6 deletions src/EBMLDecoder.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import {Buffer, readVint, ebmlBlock, convertEBMLDateToJSDate} from "./tools";
import {Int64BE} from "int64-buffer";
import * as EBML from "./EBML";
import * as tools from "./tools";
const Buffer: typeof global.Buffer = require("buffer/").Buffer;

const {byEbmlID}: {byEbmlID: { [key: number]: EBML.Schema } } = require("matroska/lib/schema");
const readVint: (buffer: Buffer, start: number)=> null | ({length: number; value: number; }) = require("ebml/lib/ebml/tools").readVint;
const ebmlBlock: (buf: Buffer)=> EBML.SimpleBlock = require("ebml-block");
import schema = require("matroska/lib/schema");
const {byEbmlID}: {byEbmlID: { [key: number]: EBML.Schema } } = schema;

// https://www.matroska.org/technical/specs/index.html

Expand Down Expand Up @@ -219,7 +217,7 @@ export default class EBMLDecoder {
// Unicode string, zero padded when needed (RFC 2279)
case "b": tagObj.value = data; break;
// Binary - not interpreted by the parser
case "d": tagObj.value = new Int64BE(data).toString(); break;
case "d": tagObj.value = convertEBMLDateToJSDate(new Int64BE(data).toNumber()); break;
// nano second; Date.UTC(2001,1,1,0,0,0,0) === 980985600000
// Date - signed 8 octets integer in nanoseconds with 0 indicating
// the precise beginning of the millennium (at 2001-01-01T00:00:00,000000000 UTC)
Expand Down
8 changes: 4 additions & 4 deletions src/EBMLEncoder.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as EBML from "./EBML";
import * as tools from "./tools";
import {Buffer, readVint, ebmlBlock} from "./tools";
import {Int64BE} from "int64-buffer";
import schema = require("matroska/lib/schema");
const {byEbmlID}: {byEbmlID: { [key: number]: EBML.Schema } } = schema;

const Buffer: typeof global.Buffer = require("buffer/").Buffer;

const {byEbmlID}: {byEbmlID: { [key: number]: EBML.Schema } } = require("matroska/lib/schema");
const writeVint: (val: number)=> Buffer = require("ebml/lib/ebml/tools").writeVint;


interface DataTree {
Expand Down
11 changes: 6 additions & 5 deletions src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#!/usr/bin/env node
import {Decoder, Encoder, tools} from './';
import EBMLReader from "./EBMLReader";
/// <reference types="node"/>
/// <reference types="commander"/>
import {Decoder, Encoder, Reader, tools} from'./';
import com = require('commander');
import fs = require('fs');
const version: string = require("../package.json").version;
const version = require("../package.json").version;

com
.version(version)
Expand All @@ -21,7 +22,7 @@ if(args.length < 1){ process.exit(); }

if(com.seekable){
const decoder = new Decoder();
const reader = new EBMLReader();
const reader = new Reader();
reader.logging = false;
reader.drop_default_duration = false;
const buf = fs.readFileSync(args[0]);
Expand All @@ -37,7 +38,7 @@ if(com.seekable){
let TrackType = -1;
let TrackNumber = -1;
let CodecID = "";
const trackTypes: {[TrackNumber: number]: {TrackType: number, CodecID: string }} = {};
const trackTypes = {} as {[TrackNumber: number]: {TrackType: number, CodecID: string }};
fs.createReadStream(args[0]).on('data', (buf)=>{
const ebmlElms = decoder.decode(buf);
ebmlElms.forEach((elm)=>{
Expand Down
5 changes: 2 additions & 3 deletions src/example_mediasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
*/

import * as EBML from './';
import {Decoder, Encoder, tools} from './';
import EBMLReader from './EBMLReader';
import {Decoder, Encoder, Reader, tools} from './';

async function main(){
const logging = true;
Expand Down Expand Up @@ -116,7 +115,7 @@ async function main(){
document.body.appendChild(button);

const decoder = new Decoder();
const reader = new EBMLReader();
const reader = new Reader();
reader.drop_default_duration = true;
reader.addListener("metadata", (ev)=>{
tasks = tasks.then(async ()=>{
Expand Down
Loading

0 comments on commit 09fceb1

Please sign in to comment.