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
+1 -1
View File
@@ -10,7 +10,7 @@ crate-type = ["cdylib"]
[dependencies] [dependencies]
# Default enable napi4 feature, see https://nodejs.org/api/n-api.html#node-api-version-matrix # 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 = [ napi = { version = "3.0.0-beta.11", default-features = false, features = [
"napi4", "napi6",
"async", "async",
"web_stream", "web_stream",
] } ] }
+1 -1
View File
@@ -53,7 +53,7 @@ test("read file offset", async (t) => {
const testString = "0123456789"; const testString = "0123456789";
fs.writeFileSync(dirName + "/TESTFILE", testString); 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 = ""; let finalString = "";
Vendored
+2 -2
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 * 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 export declare function signNonce(privateKey: string, nonce: string): string
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@drop-oss/droplet", "name": "@drop-oss/droplet",
"version": "1.5.3", "version": "1.6.0",
"main": "index.js", "main": "index.js",
"types": "index.d.ts", "types": "index.d.ts",
"napi": { "napi": {
+6 -6
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 * This is inefficient, but is used in attempt to keep the interface simple
*/ */
#[napi] #[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 path = Path::new(&path);
let mut backend = let mut backend =
create_backend_for_path(path).ok_or(napi::Error::from_reason("No backend for path"))?; 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, path: String,
sub_path: String, sub_path: String,
env: &Env, env: &Env,
start: Option<u32>, start: Option<BigInt>,
end: Option<u32>, end: Option<BigInt>,
) -> Option<ReadableStream<'_, BufferSlice<'_>>> { ) -> Option<ReadableStream<'_, BufferSlice<'_>>> {
let path = Path::new(&path); let path = Path::new(&path);
let mut backend = create_backend_for_path(path).unwrap(); let mut backend = create_backend_for_path(path).unwrap();
@@ -96,13 +96,13 @@ pub fn read_file(
let mut reader = backend.reader(&version_file)?; let mut reader = backend.reader(&version_file)?;
// Skip the 'start' amount of bytes without seek // Skip the 'start' amount of bytes without seek
if let Some(skip) = start { if let Some(skip) = start.clone() {
reader.skip(skip.into()); reader.skip(skip.get_u64().1.into());
// io::copy(&mut reader.by_ref().take(skip.into()), &mut io::sink()).unwrap(); // io::copy(&mut reader.by_ref().take(skip.into()), &mut io::sink()).unwrap();
} }
let async_reader = if let Some(limit) = end { 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 { ReadToAsyncRead {
inner: Box::new(reader.take(amount.into())), inner: Box::new(reader.take(amount.into())),
backend, backend,