diff --git a/package.json b/package.json index b251e66..b69dd6e 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@phcode/fs", "description": "Phoenix virtual file system over filer/ browser fs access/ tauri / phoenix web socket APIs", - "version": "2.0.3", + "version": "2.0.4", "keywords": [ "phoenix", "browser", diff --git a/src-tauri/node-src/phoenix-fs.js b/src-tauri/node-src/phoenix-fs.js index 6e052ac..0036ec0 100644 --- a/src-tauri/node-src/phoenix-fs.js +++ b/src-tauri/node-src/phoenix-fs.js @@ -1,10 +1,10 @@ const WebSocket = require('ws'); const fs = require("fs/promises"); +const fsNormal = require("fs"); const path = require("path"); const os = require('os'); const { exec } = require('child_process'); const chokidar = require('chokidar'); -const anymatch = require('anymatch'); const ignore = require('ignore'); const crypto = require('crypto'); @@ -255,10 +255,17 @@ function _stat(ws, metadata) { function _readBinaryFile(ws, metadata) { const fullPath = metadata.data.path; - fs.readFile(fullPath) - .then(data => { - _sendResponse(ws, metadata, {}, toArrayBuffer(data)); - }).catch((err)=>_reportError(ws, metadata, err, `Failed to read file at path ${fullPath}`)); + // fs.promises.readFile is 40% slower than fs.readFile Though we noted only minor variations is our test + // but fsNormal.readFile was faster most of the time though only by 10's of MS. + // Leaving no quick fix performance on the table, so we moved to this impl. + // https://github.com/nodejs/node/issues/37583 + fsNormal.readFile(fullPath, (err, data)=>{ + if(err) { + _reportError(ws, metadata, err, `Failed to read file at path ${fullPath}`); + return; + } + _sendResponse(ws, metadata, {}, toArrayBuffer(data)); + }); } /**