id3-wasm 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +117 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +46 -0
- package/wasm/README.md +27 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Tamás Halasi
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
# id3-wasm
|
|
2
|
+
|
|
3
|
+
A high-performance library for reading and writing ID3 tags, powered by Rust and WebAssembly.
|
|
4
|
+
|
|
5
|
+
This package provides the core JavaScript interface for the `id3-wasm` module. For a live demonstration of its capabilities, please see the [demo application](https://steve-keep.github.io/id3-wasm/).
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm add id3-wasm
|
|
11
|
+
```
|
|
12
|
+
or
|
|
13
|
+
```bash
|
|
14
|
+
npm install id3-wasm
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
The library can be used in both Node.js and modern browsers. It's fully compatible with Web Workers.
|
|
20
|
+
|
|
21
|
+
### Initializing the Module
|
|
22
|
+
|
|
23
|
+
Before using any functions, you must initialize the WebAssembly module. In a browser environment with a bundler like Vite, this is often handled automatically. In Node.js or a test environment, you may need to do it explicitly.
|
|
24
|
+
|
|
25
|
+
```javascript
|
|
26
|
+
import init from 'id3-wasm';
|
|
27
|
+
|
|
28
|
+
// This returns a promise that resolves when the Wasm module is ready.
|
|
29
|
+
await init();
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Reading Metadata from an MP3 File
|
|
33
|
+
|
|
34
|
+
To read ID3 tags, create a `TagController` from a file buffer (`Uint8Array`) and then get the metadata from it.
|
|
35
|
+
|
|
36
|
+
```javascript
|
|
37
|
+
import init, { TagController } from 'id3-wasm';
|
|
38
|
+
import * as fs from 'fs/promises';
|
|
39
|
+
|
|
40
|
+
// Initialize the Wasm module
|
|
41
|
+
await init();
|
|
42
|
+
|
|
43
|
+
// Example of reading a file in Node.js
|
|
44
|
+
const buffer = await fs.readFile('path/to/your/song.mp3');
|
|
45
|
+
const uint8Array = new Uint8Array(buffer);
|
|
46
|
+
|
|
47
|
+
let tagController;
|
|
48
|
+
let metadata;
|
|
49
|
+
try {
|
|
50
|
+
tagController = TagController.from(uint8Array);
|
|
51
|
+
metadata = tagController.getMetadata();
|
|
52
|
+
|
|
53
|
+
console.log('Title:', metadata.title);
|
|
54
|
+
console.log('Artist:', metadata.artist);
|
|
55
|
+
console.log('Album:', metadata.album);
|
|
56
|
+
console.log('Year:', metadata.year);
|
|
57
|
+
|
|
58
|
+
} catch (e) {
|
|
59
|
+
console.error('Failed to read metadata:', e);
|
|
60
|
+
} finally {
|
|
61
|
+
// IMPORTANT: The objects hold pointers to Wasm memory.
|
|
62
|
+
// You MUST free them when you are done to avoid memory leaks.
|
|
63
|
+
if (metadata) {
|
|
64
|
+
metadata.free();
|
|
65
|
+
}
|
|
66
|
+
if (tagController) {
|
|
67
|
+
tagController.free();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Modifying Metadata
|
|
73
|
+
|
|
74
|
+
The `TagController` also allows you to modify tags and write them back into a new buffer.
|
|
75
|
+
|
|
76
|
+
```javascript
|
|
77
|
+
import init, { TagController } from 'id3-wasm';
|
|
78
|
+
import * as fs from 'fs/promises';
|
|
79
|
+
|
|
80
|
+
await init();
|
|
81
|
+
|
|
82
|
+
const buffer = await fs.readFile('path/to/your/song.mp3');
|
|
83
|
+
const uint8Array = new Uint8Array(buffer);
|
|
84
|
+
|
|
85
|
+
let tagController;
|
|
86
|
+
try {
|
|
87
|
+
tagController = TagController.from(uint8Array);
|
|
88
|
+
|
|
89
|
+
// Change the metadata
|
|
90
|
+
tagController.setTitle('A New Title');
|
|
91
|
+
tagController.setArtist('A New Artist');
|
|
92
|
+
tagController.setYear(2024);
|
|
93
|
+
|
|
94
|
+
// The putTagInto method returns a *new* buffer with the updated tags.
|
|
95
|
+
const newBuffer = tagController.putTagInto(uint8Array);
|
|
96
|
+
|
|
97
|
+
// You can now save the newBuffer to a file
|
|
98
|
+
await fs.writeFile('path/to/your/new-song.mp3', newBuffer);
|
|
99
|
+
console.log('New file saved!');
|
|
100
|
+
|
|
101
|
+
} catch (e) {
|
|
102
|
+
console.error('Failed to modify metadata:', e);
|
|
103
|
+
} finally {
|
|
104
|
+
// IMPORTANT: The tagController also needs to be freed.
|
|
105
|
+
if (tagController) {
|
|
106
|
+
tagController.free();
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## API
|
|
112
|
+
|
|
113
|
+
The full API is exposed via the `TagController` and `Metadata` classes. Refer to the TypeScript definitions in `index.d.ts` for a complete list of available methods and properties.
|
|
114
|
+
|
|
115
|
+
## Contributing
|
|
116
|
+
|
|
117
|
+
Interested in contributing? Please refer to the main [README.md](../../README.md) at the root of the repository for setup, build, and testing instructions.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../wasm/id3_wasm.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../wasm/id3_wasm.js';
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "id3-wasm",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Insanely quick ID3 reading & writing for JavaScript powered by WebAssembly.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"node": {
|
|
9
|
+
"import": "./wasm/id3_wasm.js",
|
|
10
|
+
"types": "./wasm/id3_wasm.d.ts"
|
|
11
|
+
},
|
|
12
|
+
"default": {
|
|
13
|
+
"import": "./dist/index.js",
|
|
14
|
+
"types": "./dist/index.d.ts"
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://github.com/steve-keep/id3-wasm.git"
|
|
21
|
+
},
|
|
22
|
+
"keywords": [
|
|
23
|
+
"webassembly",
|
|
24
|
+
"wasm",
|
|
25
|
+
"rust",
|
|
26
|
+
"id3"
|
|
27
|
+
],
|
|
28
|
+
"bugs": {
|
|
29
|
+
"url": "https://github.com/steve-keep/id3-wasm/issues"
|
|
30
|
+
},
|
|
31
|
+
"homepage": "https://github.com/steve-keep/id3-wasm#readme",
|
|
32
|
+
"files": [
|
|
33
|
+
"wasm",
|
|
34
|
+
"dist"
|
|
35
|
+
],
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"typescript": "^5.9.3",
|
|
38
|
+
"vitest": "^1.6.1"
|
|
39
|
+
},
|
|
40
|
+
"scripts": {
|
|
41
|
+
"clean": "rm -rf ./wasm ./dist",
|
|
42
|
+
"build": "pnpm run clean && pnpm --filter rust build && mv ../rust/dist ./wasm && tsc",
|
|
43
|
+
"test": "vitest run",
|
|
44
|
+
"publish:npm": "pnpm publish --no-git-checks"
|
|
45
|
+
}
|
|
46
|
+
}
|
package/wasm/README.md
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Rust Crate for `id3-wasm`
|
|
2
|
+
|
|
3
|
+
This directory contains the core Rust crate that powers the `id3-wasm` library.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This crate is responsible for all the low-level ID3 tag parsing and manipulation. It is built upon the excellent [`id3` crate](https://crates.io/crates/id3) and exposes a simplified API for common operations, which is then compiled to WebAssembly.
|
|
8
|
+
|
|
9
|
+
The primary interface is exposed through a `TagController` struct, which is designed to be used via `wasm-bindgen` from JavaScript.
|
|
10
|
+
|
|
11
|
+
## Building
|
|
12
|
+
|
|
13
|
+
This crate is not intended to be built or used as a standalone package. It is an integral part of the `id3-wasm` monorepo.
|
|
14
|
+
|
|
15
|
+
To build the crate, you should use the root-level build command, which orchestrates the entire process of compiling the Rust code to WebAssembly and integrating it into the final JavaScript package.
|
|
16
|
+
|
|
17
|
+
For detailed instructions on how to build and test the entire project, please refer to the main [README.md](../../README.md) at the root of the repository.
|
|
18
|
+
|
|
19
|
+
### Dependencies
|
|
20
|
+
|
|
21
|
+
- `id3`: For the core ID3 logic.
|
|
22
|
+
- `wasm-bindgen`: For generating the JavaScript bindings for the WebAssembly module.
|
|
23
|
+
- `js-sys`: To interact with JavaScript types.
|
|
24
|
+
|
|
25
|
+
## Contributing
|
|
26
|
+
|
|
27
|
+
If you wish to contribute to the Rust portion of the codebase, please follow the development and testing workflow outlined in the root `README.md`. All changes to this crate should be tested through the main project's testing suite.
|