From 45c8bfa335951fa738392dc2dd69b0440bb01938 Mon Sep 17 00:00:00 2001 From: ProgrammerIn-wonderland <3838shah@gmail.com> Date: Wed, 27 Aug 2025 18:55:17 -0400 Subject: [PATCH] expose offset && byte_count in fs.read --- src/puter-js/src/modules/FileSystem/operations/read.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/puter-js/src/modules/FileSystem/operations/read.js b/src/puter-js/src/modules/FileSystem/operations/read.js index 971bc59d8..01fb42041 100644 --- a/src/puter-js/src/modules/FileSystem/operations/read.js +++ b/src/puter-js/src/modules/FileSystem/operations/read.js @@ -11,8 +11,10 @@ const read = function (...args) { // Otherwise, we assume separate arguments are provided options = { path: typeof args[0] === 'string' ? args[0] : (typeof args[0] === 'object' && args[0] !== null ? args[0].path : args[0]), - success: args[1], - error: args[2], + ...(typeof(args[1]) === "object" ? args[1]: { + success: args[1], + error: args[2], + }) }; } @@ -32,7 +34,7 @@ const read = function (...args) { options.path = getAbsolutePathForApp(options.path); // create xhr object - const xhr = utils.initXhr('/read?file=' + encodeURIComponent(options.path), this.APIOrigin, this.authToken, 'get', "application/json;charset=UTF-8", 'blob'); + const xhr = utils.initXhr('/read?' + new URLSearchParams({ file: options.path, ...(options.offset ? { offset: options.offset } : {}), ...(options.byte_count ? { byte_count: options.byte_count } : {}) }).toString(), this.APIOrigin, this.authToken, 'get', "application/json;charset=UTF-8", 'blob'); // set up event handlers for load and error events utils.setupXhrEventHandlers(xhr, options.success, options.error, resolve, reject);