{"id":15497182,"url":"https://github.com/jwerle/interchange-file-format","last_synced_at":"2025-07-13T14:36:54.326Z","repository":{"id":47310116,"uuid":"291358821","full_name":"jwerle/interchange-file-format","owner":"jwerle","description":"A module for working with Interchange File Format (IFF) data. ","archived":false,"fork":false,"pushed_at":"2021-09-03T14:37:02.000Z","size":72,"stargazers_count":7,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-27T23:43:32.692Z","etag":null,"topics":["aiff","file","fle","format","iff","interchange"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jwerle.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-08-29T22:27:24.000Z","updated_at":"2021-09-03T14:37:06.000Z","dependencies_parsed_at":"2022-09-16T09:50:25.059Z","dependency_job_id":null,"html_url":"https://github.com/jwerle/interchange-file-format","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/jwerle/interchange-file-format","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwerle%2Finterchange-file-format","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwerle%2Finterchange-file-format/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwerle%2Finterchange-file-format/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwerle%2Finterchange-file-format/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jwerle","download_url":"https://codeload.github.com/jwerle/interchange-file-format/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwerle%2Finterchange-file-format/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265156507,"owners_count":23719734,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aiff","file","fle","format","iff","interchange"],"created_at":"2024-10-02T08:31:28.670Z","updated_at":"2025-07-13T14:36:54.294Z","avatar_url":"https://github.com/jwerle.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"interchange-file-format\n=======================\n\n\u003e A module for working with Interchange File Format (IFF) data.\n\n## Installation\n\n```sh\n$ npm install interchange-file-format\n```\n\n## Example\n\nThe following example implements a few structures for the [AIFF (Audio\nInterchange File\nFormat)](http://www-mmsp.ece.mcgill.ca/Documents/AudioFormats/AIFF/Docs/AIFF-1.3.pdf)\n\n```js\nconst { Form, Chunk, extensions } = require('interchange-file-format')\nconst fs = require('fs')\n\nextensions.set('COMM', class CommonChunk extends Chunk {\n  get numChannels() { return this.readUIntBE(0, 2) }\n  get numSampleFrames() { return this.readUIntBE(2, 4) }\n  get sampleSize() { return this.readUIntBE(6, 2) }\n  get sampleRate() {\n    const x = this.readUIntBE(8, 2)\n    const y = this.readUIntBE(10, 1)\n    const z = this.readUIntBE(11, 1)\n    const pre = 16398\n    const pad = x - pre\n    const shifted = (y \u003c\u003c 8) + z\n    return shifted \u003c\u003c pad\n  }\n})\n\nextensions.set('SSND', class SoundDataChunk extends Chunk {\n  get offset() { return this.readUIntBE(0, 4) }\n  get blockSize() { return this.readUIntBE(4, 4) }\n  get soundData() { return this.slice(8) }\n})\n\nconst stream = fs.createReadStream('/path/to/audio/track.aif')\nconst form = new Form({ type: 'AIFF' })\n\nstream.pipe(form.createWriteStream()).on('finish', () =\u003e {\n  for (const chunk of form) {\n    // `chunk` could be `CommonChunk` or `SoundDataChunk` when `COMM`\n    // and `SSND` chunk IDs are foud\n    console.log(chunk)\n  }\n})\n```\n\n## API\n\n### ID\n\nThe `ID` class represents a container for 32 bits of characters, the\nconcatenation of four printable ASCII character in the range '  ' (SP, 0x20)\nthrough '~' (0x7E). Spaces (0x20) cannot precede printing characters;\ntrailing spaces are allowed. Control characters are forbidden.\n\nThe `ID` class extends `Uint8Array` and is polymorphic with the `Buffer`\nAPI.\n\n#### `id = ID.from(bufferOrString)`\n\nCreates a **4 byte** `ID` instance from a `Buffer` or string. A `Chunk`\ncan be identified by an `ID`. A `Form` will use an `ID` to describe its\ntype.\n\n```js\nconst id = ID.from('FORM')\n```\n\n##### `validated = id.set(bytes)`\n\nSet id value bytes on `ID` instance.\n\n```js\nif (!id.set(bytesOrString)) {\n  // bytes invalid or too large\n}\n```\n\n##### `buffer = id.toBuffer()`\n\nConvert `ID` instance directly to `Buffer`, using the same internal\n`ArrayBuffer` for this instance.\n\n```js\nconst buffer = id.toBuffer()\n```\n\n### Chunk\n\nThe `Chunk` class is a container for bytes with a known `ID` and size.\nA `Chunk` can be manually constructed or derived from an existing buffer\n(see `Chunk.from()`).\n\n#### `chunk = new Chunk(id, options)`\n\nCreate a new `Chunk` instance from `ID` with options where `options` can\nbe:\n\n```js\n{\n  size: required, // size in bytes of chunk body\n  ancestor: null  // the ancestor this chunk is derived from\n}\n```\n\n```js\nconst chunk = new Chunk('FORM', { size: 32 }) // 32 byte chunk body\nchunk.set(bytes) // set bytes on chunk\n```\n\n#### `chunk = Chunk.from(buffer, options)`\n\nCreate a new `Chunk` from a given `buffer` with constructor options.\n\n```js\nconst chunk = Chunk.from(bufferFromSource)\n```\n\n##### `chunk.data`\n\nA `Buffer` pointer to the `Chunk` data.\n\n##### `chunk.set(bytes[, offset])`\n\nSet bytes or a string on `Chunk`.\n\n##### `chunk = chunk.map(map)`\n\nMap over the chunks in this chunk returning a new `Chunk` instance.\n\n##### `chunk = chunk.filter(filter)`\n\nFilter over the chunks in this chunk returning a new `Chunk` instance.\n\n##### `chunk = chunk.slice(start[, stop])`\n\nCreates a new `Chunk` instance as a slice from this instance.\n\n##### `array = chunk.toArray()`\n\nConvert `Chunk`  into an `Array`.\n\n##### `buffer = chunk.toBuffer()`\n\nConverts (serializes) the `Chunk` to a `Buffer`, including the `ID` and size\nbytes as header values.\n\n### `ChunkIterator`\n\nA `Chunk` iterator that implements the _Iterator Protocol_ and\nsatisfies the _Iterable_ interface requirements.\n\n#### `iterator = ChunkIterator.from(buffer[, offset])`\n\nCreates a new `ChunkIterator` from a given `buffer` starting at an\noptional `offset`.\n\n```js\nconst iterator = ChunkIterator.from(bufferSource)\nfor (const chunk of iterator) {\n  console.log('%s', chunk.id, chunk)\n}\n```\n\n### Group\n\nAn abstract class that extends `Array` that behaves like a container that\nfor many things. Classes like `Form` and `List` extend this type for the\n`FORM` and `LIST` chunk types, respectively.\n\n#### `group = new Group(id, options)`\n\nCreates a new `Group` from a given `ID` with `options` where `option`\ncan be:\n\n```js\n{\n  type: required, // A string type name for the group, this could be the\n                  // FORM type, or the record type for a LIST\n}\n```\n\n```js\nconst group = new Group('FORM', { type: 'TEST' })\n```\n\n#### `group = Group.from(buffer)`\n\nCreates a new `Group` instance from a given buffer, loading types\nand extensions based on parsed chunk `ID`s.\n\n```js\nconst form = Group.from(bufferSource) // `bufferSource` could be a AIFF file on disk\n```\n\n##### `group.chunks`\n\nA concatenated buffer of all chunks in this group.\n\n##### `group.append(chunks)`\n\nAppend a chunk or an array of chunks to the group, setting this instance\nas the chunks ancestor.\n\n##### `group.push(...chunks)`\n\nPushes a new `Chunk` into the group, setting this instance\nas the chunks ancestor.\n\n##### `group.unshift(...chunks)`\n\n\"Unshifts\" or left pushes  a new `Chunk` into the group, setting this\ninstance as the chunks ancestor.\n\n##### `chunk = group.shift()`\n\nShift a chunk out of the group, removing a reference to this\ninstance as the ancestor.\n\n##### `chunk = group.pop()`\n\nPop a chunk out of the group, removing a reference to this\ninstance as the ancestor.\n\n##### `group = group.concat(...chunks)`\n\nConcatenates and returns a new `Group` instance with given chunks (or\n`Group`).\n\n##### `group = group.map(map)`\n\nMap over the chunks in this group returning a new `Group` instance.\n\n##### `group = group.filter(filter)`\n\nFilter over the chunks in this group returning a new `Group` instance.\n\n##### `group = group.slice(start[, stop])`\n\nCreates a new `Group` instance as a slice from this instance.\n\n##### `array = group.toArray()`\n\nConvert this instance into an `Array`.\n\n##### `buffer = group.toBuffer()`\n\nCreates a buffer from this `Group` instance flattening all\nchunks in the hierarchy.\n\n##### `stream = group.createReadStream()`\n\nGet a `ReadStream` for chunks in a `Group` instance.\n\n##### `stream = group.createWriteStream()`\n\nGet a `WriteStream` for writing chunks in a `Group` instance.\n\n### Form\n\nA `Group` type with an `ID` set to `FORM`.\n\n### List\n\nA `Group` type with an `ID` set to `LIST`.\n\n### CAT\n\nA special `Group` type with an `ID` set to `LIST` with a restriction on\nthe types of descendants being only other `Group` types.\n\n### `extensions`\n\nA static `Map` of `Group` extensions that map a 4 byte chunk `ID` string\nto a class that extends `Group` or `Chunk` to handle extensions to the\n`EA IFF 85` spec, such as `AIFF` (or `AIFC`) with the `NAME` or `SSND` types.\n\n```js\nconst { Chunk, Group, extensions } = require('interchange-file-format')\nclass TextChunk extends Chunk {\n  get text() {\n    return this.slice(0, this.size).toString()\n  }\n}\n\n// when then `NAME` or `AUTH` chunk ID is seen in a `Group`, this class will be used\nextensions.set('NAME', TextChunk)\nextensions.set('AUTH', TextChunk)\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjwerle%2Finterchange-file-format","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjwerle%2Finterchange-file-format","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjwerle%2Finterchange-file-format/lists"}