feat: move to bigints for larger file sizes

This commit is contained in:
DecDuck
2025-07-14 15:17:38 +10:00
parent e525ff44bb
commit 2969d64c45
5 changed files with 11 additions and 11 deletions

View File

@ -10,7 +10,7 @@ crate-type = ["cdylib"]
[dependencies]
# Default enable napi4 feature, see https://nodejs.org/api/n-api.html#node-api-version-matrix
napi = { version = "3.0.0-beta.11", default-features = false, features = [
"napi4",
"napi6",
"async",
"web_stream",
] }

View File

@ -53,7 +53,7 @@ test("read file offset", async (t) => {
const testString = "0123456789";
fs.writeFileSync(dirName + "/TESTFILE", testString);
const stream = droplet.readFile(dirName, "TESTFILE", 1, 4);
const stream = droplet.readFile(dirName, "TESTFILE", BigInt(1), BigInt(4));
let finalString = "";

4
index.d.ts vendored
View File

@ -15,9 +15,9 @@ export declare function listFiles(path: string): Array<string>
/**
* This is inefficient, but is used in attempt to keep the interface simple
*/
export declare function peekFile(path: string, subPath: string): number
export declare function peekFile(path: string, subPath: string): bigint
export declare function readFile(path: string, subPath: string, start?: number | undefined | null, end?: number | undefined | null): ReadableStream<Buffer> | null
export declare function readFile(path: string, subPath: string, start?: bigint | undefined | null, end?: bigint | undefined | null): ReadableStream<Buffer> | null
export declare function signNonce(privateKey: string, nonce: string): string

View File

@ -1,6 +1,6 @@
{
"name": "@drop-oss/droplet",
"version": "1.5.3",
"version": "1.6.0",
"main": "index.js",
"types": "index.d.ts",
"napi": {

View File

@ -64,7 +64,7 @@ pub fn list_files(path: String) -> Result<Vec<String>> {
* This is inefficient, but is used in attempt to keep the interface simple
*/
#[napi]
pub fn peek_file(path: String, sub_path: String) -> Result<u32> {
pub fn peek_file(path: String, sub_path: String) -> Result<u64> {
let path = Path::new(&path);
let mut backend =
create_backend_for_path(path).ok_or(napi::Error::from_reason("No backend for path"))?;
@ -82,8 +82,8 @@ pub fn read_file(
path: String,
sub_path: String,
env: &Env,
start: Option<u32>,
end: Option<u32>,
start: Option<BigInt>,
end: Option<BigInt>,
) -> Option<ReadableStream<'_, BufferSlice<'_>>> {
let path = Path::new(&path);
let mut backend = create_backend_for_path(path).unwrap();
@ -96,13 +96,13 @@ pub fn read_file(
let mut reader = backend.reader(&version_file)?;
// Skip the 'start' amount of bytes without seek
if let Some(skip) = start {
reader.skip(skip.into());
if let Some(skip) = start.clone() {
reader.skip(skip.get_u64().1.into());
// io::copy(&mut reader.by_ref().take(skip.into()), &mut io::sink()).unwrap();
}
let async_reader = if let Some(limit) = end {
let amount = limit - start.or(Some(0)).unwrap();
let amount = limit.get_u64().1 - start.map_or(Some(0), |v| Some(v.get_u64().1)).unwrap();
ReadToAsyncRead {
inner: Box::new(reader.take(amount.into())),
backend,