Skip to content

Commit

Permalink
Completed web.js HSSP 5 support and some last fixes before 4.0.0 release
Browse files Browse the repository at this point in the history
  • Loading branch information
Le0X8 authored Aug 24, 2023
1 parent a3cff9a commit 61fe779
Show file tree
Hide file tree
Showing 5 changed files with 619 additions and 134 deletions.
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Continue with [learning about the API](#api).
### Web
- Load HSSP for JavaScript with:
```html
<script src="https://cdn.jsdelivr.net/npm/hssp@3/web.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/hssp@4/web.min.js"></script>
```
- Create an editor:
```js
Expand Down Expand Up @@ -62,6 +62,7 @@ editor.addFile('my-folder/test.txt', fs.readFileSync('test2.txt'));
editor.addFile('my-folder/test.txt', (new TextEncoder()).encode('Hello, world! 2').buffer);
```
- Delete a file:

**Note:** _This method will return the file Buffer/ArrayBuffer._
```js
editor.remove('test.txt');
Expand All @@ -70,6 +71,7 @@ editor.remove('test.txt');
```js
editor.remove('my-folder');
```

**Note:** _This will only remove the folder, not the files in it! If you want to remove the folder with the files in it, use:_
```js
var folderName = 'my-folder';
Expand All @@ -85,7 +87,7 @@ editor.remove(folderName); // Remove the folder itself

- Set output file version:
```js
editor.version = 4; // 4 is set by default, 1-4 are valid version numbers
editor.version = 5; // 5 is set by default, 1-5 are valid version numbers
```
- Enable output encryption:
```js
Expand All @@ -96,6 +98,7 @@ editor.password = 'MySecretPassword'; // write-only
editor.password = null; // Encryption is disabled by default
```
- Enable output compression ([Supported algorithms](#supported-compression-algorithms)):

**Note:** _Requires editor.version is 4 or higher._
```js
editor.compression = { algorithm: 'LZMA', level: 9 }; // Level default is 5
Expand All @@ -105,14 +108,15 @@ editor.compression = { algorithm: 'LZMA', level: 9 }; // Level default is 5
editor.compression = null; // default
```
- Add a comment:

**Note:** _Requires editor.version is 4 or higher. The comment can be up to 16 characters (UTF-8) long._
```js
editor.comment = 'Hello :)';
```

#### Importing HSSP files

Currently supports HSSP 1-4.
Currently supports HSSP 1-5.

- Importing HSSP files _without_ encryption:
```js
Expand Down Expand Up @@ -145,7 +149,7 @@ document.querySelector('input[type=file]').onchange = async (ev) => {

#### Creating HSSP files

Currently supports HSSP 1-4.
Currently supports HSSP 1-5.

- Creating _one_ file:
```js
Expand All @@ -162,6 +166,7 @@ a.click();
URL.revokeObjectURL(url);
```
- Creating _multiple_ files:

**Note:** _This method can only be used if `editor.version` is 4 or higher. You also cannot create more files than bytes included._
```js
// Node
Expand All @@ -185,7 +190,7 @@ editor.toBuffers(4).forEach((buf, i) => {

#### Fetching metadata from HSSP file

Currently supports HSSP 1-4.
Currently supports HSSP 1-5.

Fetching metadata is as simple as that:
```js
Expand Down Expand Up @@ -236,7 +241,7 @@ editor.addFolder(name, options);

Feel free to contribute by [opening an issue](https://github.com/HSSPfile/js/issues/new/choose) and requesting new features, reporting bugs or just asking questions.

You can also [fork the repository](https://github.com/HSSPfile/js/fork) and opening a [pull request](https://github.com/HSSPfile/js/pulls) after making some changes like fixing bugs.
You can also [fork the repository](https://github.com/HSSPfile/js/fork) and open a [pull request](https://github.com/HSSPfile/js/pulls) after making some changes like fixing bugs.

## [License](LICENSE)

Expand Down
8 changes: 4 additions & 4 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1175,7 +1175,7 @@ class Editor { // Can hold massive amounts of data in a single file
var fileStart = Buffer.alloc(size);
fileStart.write('HSSP', 0, 'utf8'); // Magic value :) | 4+0
fileStart.writeUint8(4, 4); // File standard version, see https://hssp.leox.dev/docs/versions | 1+4
out.writeUint8(parseInt([
fileStart.writeUint8(parseInt([
this.#pwd !== null, // F1: is encrypted
this.#compAlgo !== 'NONE', // F2: is compressed
true, // F3: is split
Expand All @@ -1185,7 +1185,7 @@ class Editor { // Can hold massive amounts of data in a single file
false, // F7: unallocated
false // F8: unallocated
].map(b => +b).join(''), 2), 5); // Flags #1, see https://hssp.leox.dev/docs/flags | 1+5
out.writeUint8(parseInt([
fileStart.writeUint8(parseInt([
false, // F9: unallocated
false, // F10: unallocated
false, // F11: unallocated
Expand All @@ -1195,7 +1195,7 @@ class Editor { // Can hold massive amounts of data in a single file
false, // F15: unallocated
false // F16: unallocated
].map(b => +b).join(''), 2), 6); // Flags #2, see https://hssp.leox.dev/docs/flags | 1+6
out.writeUint8(parseInt([
fileStart.writeUint8(parseInt([
false, // F17: unallocated
false, // F18: unallocated
false, // F19: unallocated
Expand Down Expand Up @@ -1660,7 +1660,7 @@ module.exports = {
return metadata;

case 5: // v5: Uses flags
metadata.version = 4;
metadata.version = 5;
const inp = buffer.subarray(128, buffer.byteLength);
metadata.hash.valid = true;
const hash = murmurhash.murmur3(inp.toString('utf8'), 0x31082007);
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hssp",
"version": "3.0.0",
"version": "4.0.0",
"description": "Create, edit and read HSSP files in pure JavaScript",
"main": "main.js",
"scripts": {
Expand All @@ -11,8 +11,7 @@
"HSSP",
"HugeSizeSupportingPackage",
"Huge",
"Package",
"64RiB"
"Package"
],
"author": "HSSP",
"license": "MIT",
Expand Down
Loading

0 comments on commit 61fe779

Please sign in to comment.