# rustworld

> Install the RustWorldJS package into your project ``` npm install rustworld ```

Latest version **1.0.3** (published 2023-10-22) · BSD-2-Clause license · 0 weekly downloads

## Install

```sh
npm install rustworld
pnpm add rustworld
yarn add rustworld
bun add rustworld
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2023-10-22 |
| First published | 2022-10-21 |
| Weekly downloads | 0 |
| License | BSD-2-Clause |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 47.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Maintainers | dezinated |

## Links

- npm: https://www.npmjs.com/package/rustworld
- Repository: https://github.com/Dezinater/RustWorldJS
- Homepage: https://github.com/Dezinater/RustWorldJS#readme
- Issues: https://github.com/Dezinater/RustWorldJS/issues
- npm.io page: https://npm.io/package/rustworld

## Dependencies (2)

- [protobufjs](https://npm.io/package/protobufjs.md) ^7.1.1
- [web-worker](https://npm.io/package/web-worker.md) ^1.2.0

## Recent versions

- 1.0.3 (latest) — 2023-10-22
- 1.0.2 — 2023-07-04
- 1.0.1 — 2023-04-16
- 1.0.0 — 2022-10-21

## README

# RustWorldJS

## Getting Started

Install the RustWorldJS package into your project
```
npm install rustworld
```


## Usage

```javascript
import * as rustWorld from "rustworld";

import * as fs from "fs";
import { dirname } from 'path';
import { fileURLToPath } from 'url';

const __dirname = dirname(fileURLToPath(import.meta.url));

fs.readFile(__dirname + '/../../test/test.map', function (err, fileContents) {
    let world = rustWorld.readMap(fileContents);

    rustWorld.writeMap(world).then(bytes => {
        // write bytes to file
    });
});
```

The package comes with Typescript definitions so if you are using Typescript you will be able to see every method and class available to use. To get started take a look at the examples for some code samples.

 - [generate-circle-plots](https://github.com/Dezinater/RustWorldJS/tree/master/examples/generate-circle-plots)
 - [get-map-size](https://github.com/Dezinater/RustWorldJS/tree/master/examples/get-map-size)
 - [get-terrainmap-info](https://github.com/Dezinater/RustWorldJS/tree/master/examples/get-terrainmap-info)
 - [ice-walls](https://github.com/Dezinater/RustWorldJS/tree/master/examples/ice-walls)


## LZ4 Compression

The original [Rust.World SDK](https://github.com/Facepunch/Rust.World) and the game itself uses LZ4 compression for map reading and writing. They use a library called [lz4net](https://github.com/MiloszKrajewski/lz4net) which is now outdated and has a custom implementation of LZ4. RustWorldJS recreates and uses that same custom implementation of LZ4. 

This custom LZ4 format is a header for LZ4 data which means any LZ4 library can be used to read and write Rust maps if it can read and write the header. To recreate this custom LZ4 format in another language take a look at [LZ4Reader.ts](https://github.com/Dezinater/RustWorldJS/blob/master/src/LZ4Reader.ts#L52) and [worker.cts](https://github.com/Dezinater/RustWorldJS/blob/master/src/worker.cts#L30) for an example on how the header is used.

The LZ4 library used in RustWorldJS is [lz4js](https://github.com/Benzinga/lz4js) but modified to use a hashing method from [lz4net](https://github.com/MiloszKrajewski/lz4net)

---
_Source: https://npm.io/package/rustworld · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
