midifile-ts
Advanced tools
Comparing version 1.0.1 to 1.0.2
{ | ||
"name": "midifile-ts", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -38,7 +38,8 @@ import toCharCodes from "./toCharCodes" | ||
this.writeStr(id) | ||
this.writeInt32(0) // dummy chunk size | ||
const start = this.length | ||
func(this) // write chunk contents | ||
const size = this.length - start | ||
this.writeInt32(size) // write chunk size | ||
const chunkBuf = new Buffer() | ||
func(chunkBuf) | ||
this.writeInt32(chunkBuf.length) | ||
this.writeBytes(chunkBuf.data) | ||
} | ||
@@ -45,0 +46,0 @@ |
@@ -1,2 +0,2 @@ | ||
export type StreamSource = DataView | number[] | ArrayBuffer | Buffer | ||
export type StreamSource = DataView | number[] | ArrayBuffer | Buffer | Uint8Array | ||
@@ -17,2 +17,6 @@ /* Wrapper for accessing strings through sequential reads */ | ||
this.buf = new DataView(new Uint8Array(buf).buffer) | ||
} else if (buf instanceof Uint8Array) { | ||
this.buf = new DataView(buf.buffer) | ||
} else { | ||
throw new Error("not supported type: " + (typeof buf)) | ||
} | ||
@@ -19,0 +23,0 @@ } |
import assert from "assert" | ||
import write from "./write" | ||
import read from "./read" | ||
import fs from "fs" | ||
@@ -9,2 +11,9 @@ describe("reader", () => { | ||
}) | ||
it("read and write back", () => { | ||
const data = fs.readFileSync("./fixtures/tracks.mid") | ||
const midiA = read(data) | ||
const bytes = write(midiA.tracks, midiA.header.ticksPerBeat) | ||
const midiB = read(bytes) | ||
assert.equal(midiA.tracks.length, midiB.tracks.length) | ||
}) | ||
}) |
144926
2346