Skip to content

Commit

Permalink
a
Browse files Browse the repository at this point in the history
  • Loading branch information
legokichi committed Feb 21, 2024
1 parent 0cf69b9 commit cd79c16
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 33 deletions.
20 changes: 10 additions & 10 deletions dist/EBML.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ var State;
})(State || (State = {}));
class EBMLDecoder {
constructor() {
this._buffer = tools_1.Buffer.from(new ArrayBuffer(0));
this._buffer = tools_1.Buffer.alloc(0);
this._tag_stack = [];
this._state = State.STATE_TAG;
this._cursor = 0;
Expand Down Expand Up @@ -391,7 +391,7 @@ class EBMLEncoder {
}
// 閉じタグ不定長の場合はスタックに積まずに即時バッファに書き込む
if (elm.unknownSize) {
const data = tools.encodeTag(tagId, Buffer.from(new ArrayBuffer(0)), elm.unknownSize);
const data = tools.encodeTag(tagId, Buffer.alloc(0), elm.unknownSize);
this._buffers = this._buffers.concat(data);
return;
}
Expand Down Expand Up @@ -1004,14 +1004,14 @@ exports.VP8BitStreamToRiffWebPBuffer = VP8BitStreamToRiffWebPBuffer;
* RIFF データチャンクを作る
*/
function createRIFFChunk(FourCC, chunk) {
const chunkSize = buffer_1.Buffer.from(new ArrayBuffer(4));
const chunkSize = buffer_1.Buffer.alloc(4);
chunkSize.writeUInt32LE(chunk.byteLength, 0);
return concat([
buffer_1.Buffer.from(FourCC.substring(0, 4), "ascii"),
chunkSize,
chunk,
// padding
buffer_1.Buffer.from(new ArrayBuffer(chunk.byteLength % 2 === 0 ? 0 : 1))
buffer_1.Buffer.alloc(chunk.byteLength % 2 === 0 ? 0 : 1)
]);
}
exports.createRIFFChunk = createRIFFChunk;
Expand Down Expand Up @@ -1650,7 +1650,7 @@ function concat(list) {
}
exports.concat = concat;
function encodeValueToBuffer(elm) {
let data = buffer_1.Buffer.from(new ArrayBuffer(0));
let data = buffer_1.Buffer.alloc(0);
if (elm.type === "m") {
return elm;
}
Expand Down Expand Up @@ -1691,7 +1691,7 @@ function createUIntBuffer(value) {
console.warn("7bit or more bigger uint not supported.");
return new int64_buffer_1.Uint64BE(value).toBuffer();
}
const data = buffer_1.Buffer.from(new ArrayBuffer(bytes));
const data = buffer_1.Buffer.alloc(bytes);
data.writeUIntBE(value, 0, bytes);
return data;
}
Expand All @@ -1706,7 +1706,7 @@ function createIntBuffer(value) {
console.warn("7bit or more bigger uint not supported.");
return new int64_buffer_1.Int64BE(value).toBuffer();
}
const data = buffer_1.Buffer.from(new ArrayBuffer(bytes));
const data = buffer_1.Buffer.alloc(bytes);
data.writeIntBE(value, 0, bytes);
return data;
}
Expand All @@ -1716,13 +1716,13 @@ function createFloatBuffer(value, bytes = 8) {
// js number is float64 so 8 bytes.
if (bytes === 8) {
// 64bit
const data = buffer_1.Buffer.from(new ArrayBuffer(8));
const data = buffer_1.Buffer.alloc(8);
data.writeDoubleBE(value, 0);
return data;
}
else if (bytes === 4) {
// 32bit
const data = buffer_1.Buffer.from(new ArrayBuffer(4));
const data = buffer_1.Buffer.alloc(4);
data.writeFloatBE(value, 0);
return data;
}
Expand Down Expand Up @@ -18600,7 +18600,7 @@ process.umask = function() { return 0; };
},{}],21:[function(require,module,exports){
module.exports={
"name": "ts-ebml",
"version": "2.0.2",
"version": "3.0.0",
"description": "ebml decoder and encoder",
"scripts": {
"clean": "rimraf lib/* dist/* test/*.js",
Expand Down
2 changes: 1 addition & 1 deletion dist/EBML.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/EBMLDecoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var State;
})(State || (State = {}));
class EBMLDecoder {
constructor() {
this._buffer = tools_1.Buffer.from(new ArrayBuffer(0));
this._buffer = tools_1.Buffer.alloc(0);
this._tag_stack = [];
this._state = State.STATE_TAG;
this._cursor = 0;
Expand Down
2 changes: 1 addition & 1 deletion lib/EBMLEncoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class EBMLEncoder {
}
// 閉じタグ不定長の場合はスタックに積まずに即時バッファに書き込む
if (elm.unknownSize) {
const data = tools.encodeTag(tagId, Buffer.from(new ArrayBuffer(0)), elm.unknownSize);
const data = tools.encodeTag(tagId, Buffer.alloc(0), elm.unknownSize);
this._buffers = this._buffers.concat(data);
return;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/test.js

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions lib/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ exports.VP8BitStreamToRiffWebPBuffer = VP8BitStreamToRiffWebPBuffer;
* RIFF データチャンクを作る
*/
function createRIFFChunk(FourCC, chunk) {
const chunkSize = buffer_1.Buffer.from(new ArrayBuffer(4));
const chunkSize = buffer_1.Buffer.alloc(4);
chunkSize.writeUInt32LE(chunk.byteLength, 0);
return concat([
buffer_1.Buffer.from(FourCC.substring(0, 4), "ascii"),
chunkSize,
chunk,
// padding
buffer_1.Buffer.from(new ArrayBuffer(chunk.byteLength % 2 === 0 ? 0 : 1))
buffer_1.Buffer.alloc(chunk.byteLength % 2 === 0 ? 0 : 1)
]);
}
exports.createRIFFChunk = createRIFFChunk;
Expand Down Expand Up @@ -730,7 +730,7 @@ function concat(list) {
}
exports.concat = concat;
function encodeValueToBuffer(elm) {
let data = buffer_1.Buffer.from(new ArrayBuffer(0));
let data = buffer_1.Buffer.alloc(0);
if (elm.type === "m") {
return elm;
}
Expand Down Expand Up @@ -771,7 +771,7 @@ function createUIntBuffer(value) {
console.warn("7bit or more bigger uint not supported.");
return new int64_buffer_1.Uint64BE(value).toBuffer();
}
const data = buffer_1.Buffer.from(new ArrayBuffer(bytes));
const data = buffer_1.Buffer.alloc(bytes);
data.writeUIntBE(value, 0, bytes);
return data;
}
Expand All @@ -786,7 +786,7 @@ function createIntBuffer(value) {
console.warn("7bit or more bigger uint not supported.");
return new int64_buffer_1.Int64BE(value).toBuffer();
}
const data = buffer_1.Buffer.from(new ArrayBuffer(bytes));
const data = buffer_1.Buffer.alloc(bytes);
data.writeIntBE(value, 0, bytes);
return data;
}
Expand All @@ -796,13 +796,13 @@ function createFloatBuffer(value, bytes = 8) {
// js number is float64 so 8 bytes.
if (bytes === 8) {
// 64bit
const data = buffer_1.Buffer.from(new ArrayBuffer(8));
const data = buffer_1.Buffer.alloc(8);
data.writeDoubleBE(value, 0);
return data;
}
else if (bytes === 4) {
// 32bit
const data = buffer_1.Buffer.from(new ArrayBuffer(4));
const data = buffer_1.Buffer.alloc(4);
data.writeFloatBE(value, 0);
return data;
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ts-ebml",
"version": "2.0.2",
"version": "3.0.0",
"description": "ebml decoder and encoder",
"scripts": {
"clean": "rimraf lib/* dist/* test/*.js",
Expand Down
2 changes: 1 addition & 1 deletion src/EBMLDecoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default class EBMLDecoder {
private _result: EBML.EBMLElementDetail[];

constructor() {
this._buffer = Buffer.from(new ArrayBuffer(0));
this._buffer = Buffer.alloc(0);
this._tag_stack = [];
this._state = State.STATE_TAG;
this._cursor = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/EBMLEncoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export default class EBMLEncoder {
if (elm.unknownSize) {
const data = tools.encodeTag(
tagId,
Buffer.from(new ArrayBuffer(0)),
Buffer.alloc(0),
elm.unknownSize
);
this._buffers = this._buffers.concat(data);
Expand Down
2 changes: 1 addition & 1 deletion src/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ QUnit.test("handwrite-encoder", (assert: Assert) => {
{
name: "SimpleBlock",
type: "b",
value: Buffer.from(new ArrayBuffer(1024))
value: Buffer.alloc(1024)
}
];
const binarized = tagStream.map((o: MasterElement | ChildElementsValue) =>
Expand Down
14 changes: 7 additions & 7 deletions src/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,14 @@ export function VP8BitStreamToRiffWebPBuffer(frame: Buffer): Buffer {
* RIFF データチャンクを作る
*/
export function createRIFFChunk(FourCC: string, chunk: Buffer): Buffer {
const chunkSize = Buffer.from(new ArrayBuffer(4));
const chunkSize = Buffer.alloc(4);
chunkSize.writeUInt32LE(chunk.byteLength, 0);
return concat([
Buffer.from(FourCC.substring(0, 4), "ascii"),
chunkSize,
chunk,
// padding
Buffer.from(new ArrayBuffer(chunk.byteLength % 2 === 0 ? 0 : 1))
Buffer.alloc(chunk.byteLength % 2 === 0 ? 0 : 1)
]);
}

Expand Down Expand Up @@ -838,7 +838,7 @@ export function encodeValueToBuffer(
export function encodeValueToBuffer(
elm: EBML.EBMLElementValue
): EBML.EBMLElementBuffer {
let data = Buffer.from(new ArrayBuffer(0));
let data = Buffer.alloc(0);
if (elm.type === "m") {
return elm;
}
Expand Down Expand Up @@ -879,7 +879,7 @@ export function createUIntBuffer(value: number): Buffer {
console.warn("7bit or more bigger uint not supported.");
return new Uint64BE(value).toBuffer();
}
const data = Buffer.from(new ArrayBuffer(bytes));
const data = Buffer.alloc(bytes);
data.writeUIntBE(value, 0, bytes);
return data;
}
Expand All @@ -894,7 +894,7 @@ export function createIntBuffer(value: number): Buffer {
console.warn("7bit or more bigger uint not supported.");
return new Int64BE(value).toBuffer();
}
const data = Buffer.from(new ArrayBuffer(bytes));
const data = Buffer.alloc(bytes);
data.writeIntBE(value, 0, bytes);
return data;
}
Expand All @@ -904,12 +904,12 @@ export function createFloatBuffer(value: number, bytes: 4 | 8 = 8): Buffer {
// js number is float64 so 8 bytes.
if (bytes === 8) {
// 64bit
const data = Buffer.from(new ArrayBuffer(8));
const data = Buffer.alloc(8);
data.writeDoubleBE(value, 0);
return data;
} else if (bytes === 4) {
// 32bit
const data = Buffer.from(new ArrayBuffer(4));
const data = Buffer.alloc(4);
data.writeFloatBE(value, 0);
return data;
} else {
Expand Down

0 comments on commit cd79c16

Please sign in to comment.