Skip to content

Commit b30bb29

Browse files
committed
chore: run linter
1 parent d1a6875 commit b30bb29

26 files changed

Lines changed: 117 additions & 103 deletions

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ Binarystream is a simple Rust package designed to simplify the streaming of bina
55
## Example Usage
66

77
```ts
8-
import { BinaryStream } from "@serenityjs/binarystream"
8+
import { BinaryStream } from '@serenityjs/binarystream'
99

1010
// Create a new stream without a given buffer.
1111
const stream = new BinaryStream()
1212

1313
// Reading / Writing is allowed on the fly,
1414
// which will automatically update the cursor offset depending on the type of call.
1515
stream.writeUint8(255)
16-
stream.writeString16("Hello, World!")
16+
stream.writeString16('Hello, World!')
1717

1818
// Converting the stream to a buffer!
1919
const buffer = stream.getBuffer()
@@ -24,5 +24,4 @@ const output = new BinaryStream(buffer)
2424
// Reading the data in order.
2525
stream.readUint8() // Expected output: 255
2626
stream.readString16() // Expected output: "Hello, World!"
27-
28-
```
27+
```

index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,5 +223,5 @@ export declare class ZigZong {
223223

224224
export declare const enum Endianness {
225225
Big = 0,
226-
Little = 1
226+
Little = 1,
227227
}

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
pub mod stream;
21
pub mod endianness;
2+
pub mod stream;
33
pub mod types;

src/stream.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
use napi_derive::napi;
22

3-
use napi::{bindgen_prelude::{BufferSlice, JsValuesTuple}, Env, Result};
3+
use napi::{
4+
bindgen_prelude::{BufferSlice, JsValuesTuple},
5+
Env, Result,
6+
};
47

58
#[napi]
69
pub struct BinaryStream<'env> {
710
/**
811
* The buffer reference that this stream will read/write to.
9-
*/
12+
*/
1013
buffer: BufferSlice<'env>,
1114

1215
/**
1316
* The current offset in the buffer where the next read/write will occur.
14-
*/
17+
*/
1518
offset: usize,
1619
}
1720

@@ -67,7 +70,7 @@ impl<'env> BinaryStream<'env> {
6770

6871
/**
6972
* Returns the current offset in the stream.
70-
*/
73+
*/
7174
#[napi(js_name = "getOffset")]
7275
pub fn get_offset_napi(&self) -> Result<u32> {
7376
// Cast the offset to u32 and return it
@@ -77,7 +80,7 @@ impl<'env> BinaryStream<'env> {
7780
/**
7881
* Sets the current offset in the stream.
7982
* If the offset is out of bounds, it returns an error.
80-
*/
83+
*/
8184
#[napi(js_name = "setOffset")]
8285
pub fn set_offset_napi(&mut self, offset: u32) -> Result<()> {
8386
// Check if the offset is within the bounds of the buffer
@@ -113,7 +116,7 @@ impl<'env> BinaryStream<'env> {
113116
Ok(())
114117
}
115118

116-
#[napi(js_name = "read")]
119+
#[napi(js_name = "read")]
117120
pub fn read_napi(&mut self, length: u32) -> Result<BufferSlice<'env>> {
118121
// Check if the read will exceed the buffer length
119122
if self.offset + length as usize > self.buffer.len() {
@@ -133,16 +136,16 @@ impl<'env> BinaryStream<'env> {
133136
let env = &Env::from_raw(self.buffer.env());
134137

135138
// Create a BufferSlice from the slice
136-
let buffer = BufferSlice::from_data(env, slice)
137-
.expect("Failed to create BufferSlice from data");
139+
let buffer =
140+
BufferSlice::from_data(env, slice).expect("Failed to create BufferSlice from data");
138141

139142
// Return the slice as a BufferSlice
140143
Ok(buffer)
141144
}
142145

143146
/**
144147
* Checks if the stream has reached the end of the buffer.
145-
*/
148+
*/
146149
#[napi]
147150
pub fn feof(&self) -> bool {
148151
// Check if the current offset is at the end of the buffer
@@ -151,10 +154,10 @@ impl<'env> BinaryStream<'env> {
151154

152155
/**
153156
* Resets the stream's offset to the beginning of the buffer.
154-
*/
157+
*/
155158
#[napi]
156159
pub fn reset(&mut self) {
157160
// Reset the offset to 0
158161
self.offset = 0;
159162
}
160-
}
163+
}

src/types/bool.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub struct Bool();
1010
impl Bool {
1111
/**
1212
* Read a boolean value (u8) from the BinaryStream.
13-
*/
13+
*/
1414
#[napi]
1515
pub fn read(stream: &mut BinaryStream) -> Result<bool> {
1616
// Read a single byte from the stream
@@ -25,7 +25,7 @@ impl Bool {
2525

2626
/**
2727
* Write a boolean value (u8) to the BinaryStream.
28-
*/
28+
*/
2929
#[napi]
3030
pub fn write(stream: &mut BinaryStream, value: bool) -> Result<()> {
3131
// Convert the boolean value to a byte (1 for true, 0 for false)
@@ -37,4 +37,4 @@ impl Bool {
3737
Err(err) => Err(err),
3838
}
3939
}
40-
}
40+
}

src/types/float/float32.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use napi::Result;
22
use napi_derive::napi;
33

4-
use crate::stream::BinaryStream;
54
use crate::endianness::Endianness;
5+
use crate::stream::BinaryStream;
66

77
#[napi]
88
pub struct Float32();
@@ -11,7 +11,7 @@ pub struct Float32();
1111
impl Float32 {
1212
/**
1313
* Read a 32-bit floating point number (f32) from the BinaryStream.
14-
*/
14+
*/
1515
#[napi]
1616
pub fn read(stream: &mut BinaryStream, endian: Option<Endianness>) -> Result<f64> {
1717
// Provide a default endianness if not specified
@@ -32,7 +32,7 @@ impl Float32 {
3232

3333
/**
3434
* Write a 32-bit floating point number (f32) to the BinaryStream.
35-
*/
35+
*/
3636
#[napi]
3737
pub fn write(stream: &mut BinaryStream, value: f64, endian: Option<Endianness>) -> Result<()> {
3838
// Provide a default endianness if not specified
@@ -50,4 +50,4 @@ impl Float32 {
5050
Err(err) => Err(err),
5151
}
5252
}
53-
}
53+
}

src/types/float/float64.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use napi::Result;
22
use napi_derive::napi;
33

4-
use crate::stream::BinaryStream;
54
use crate::endianness::Endianness;
5+
use crate::stream::BinaryStream;
66

77
#[napi]
88
pub struct Float64();
@@ -11,7 +11,7 @@ pub struct Float64();
1111
impl Float64 {
1212
/**
1313
* Read a 64-bit floating point number (f64) from the BinaryStream.
14-
*/
14+
*/
1515
#[napi]
1616
pub fn read(stream: &mut BinaryStream, endian: Option<Endianness>) -> Result<f64> {
1717
// Provide a default endianness if not specified
@@ -25,14 +25,18 @@ impl Float64 {
2525

2626
// Convert the bytes to f64 based on endianness
2727
match endian {
28-
Endianness::Big => Ok(f64::from_be_bytes([bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6], bytes[7]])),
29-
Endianness::Little => Ok(f64::from_le_bytes([bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6], bytes[7]])),
28+
Endianness::Big => Ok(f64::from_be_bytes([
29+
bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6], bytes[7],
30+
])),
31+
Endianness::Little => Ok(f64::from_le_bytes([
32+
bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6], bytes[7],
33+
])),
3034
}
3135
}
3236

3337
/**
3438
* Write a 64-bit floating point number (f64) to the BinaryStream.
35-
*/
39+
*/
3640
#[napi]
3741
pub fn write(stream: &mut BinaryStream, value: f64, endian: Option<Endianness>) -> Result<()> {
3842
// Provide a default endianness if not specified
@@ -50,4 +54,4 @@ impl Float64 {
5054
Err(err) => Err(err),
5155
}
5256
}
53-
}
57+
}

src/types/float/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
pub mod float32;
2-
pub mod float64;
2+
pub mod float64;

src/types/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
pub mod bool;
2+
pub mod float;
13
pub mod signed;
2-
pub mod unsigned;
34
pub mod string;
4-
pub mod float;
5-
pub mod bool;
5+
pub mod unsigned;

src/types/signed/int16.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use napi::Result;
22
use napi_derive::napi;
33

4-
use crate::stream::BinaryStream;
54
use crate::endianness::Endianness;
5+
use crate::stream::BinaryStream;
66

77
#[napi]
88
pub struct Int16();
@@ -11,7 +11,7 @@ pub struct Int16();
1111
impl Int16 {
1212
/**
1313
* Read a unsigned 16-bit integer (i16) from the BinaryStream.
14-
*/
14+
*/
1515
#[napi]
1616
pub fn read(stream: &mut BinaryStream, endian: Option<Endianness>) -> Result<i16> {
1717
// Provide a default endianness if not specified
@@ -32,7 +32,7 @@ impl Int16 {
3232

3333
/**
3434
* Write a unsigned 16-bit integer (i16) to the BinaryStream.
35-
*/
35+
*/
3636
#[napi]
3737
pub fn write(stream: &mut BinaryStream, value: i16, endian: Option<Endianness>) -> Result<()> {
3838
// Provide a default endianness if not specified
@@ -50,4 +50,4 @@ impl Int16 {
5050
Err(err) => Err(err),
5151
}
5252
}
53-
}
53+
}

0 commit comments

Comments
 (0)