-
Notifications
You must be signed in to change notification settings - Fork 29.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fs.ReadFile
throws asynchronously with encoding on large enough input
#2767
Comments
fs.ReadFile
throws asynchronously with utf8
encoding on large enough inputfs.ReadFile
throws asynchronously with encoding on large enough input
AFAIK V8 can optimize functions with |
p.s. Sorry it is just |
And only with TF ( |
@bnoordhuis are you sure? from
|
depends what is the effect of the |
Nothing until you specify (Strictly speaking, You can check for yourself with |
I have this problem too |
In fs.readFile, if an encoding is specified and toString fails, do not throw an error. Instead, pass the error to the callback. Fixes: nodejs#2767 PR-URL: nodejs#3485 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Trevor Norris <[email protected]>
Fixed in b620790 |
In fs.readFile, if an encoding is specified and toString fails, do not throw an error. Instead, pass the error to the callback. Fixes: #2767 PR-URL: #3485 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Trevor Norris <[email protected]>
on node 5x get the same error while trying ti use handlebars with readfile |
@NikosEfthias Can you tell me the specific version and platform you are using? |
@evanlucas solved the issue the problem was that handlebars couldnt turn buffer into string when i call data.toString() no problem |
Hi, I am trying to read codiegniter cache file, In this file data stored in serialize, When i try to read it retrun proper data but some time break serialize string data and throw error. Please check below error : I have try below code :
and i got below errors :
Can you provide me solution, Thanks in Advance |
@girishp15 That looks neither related nor an issue with node.js core. Please don't hijack issues. |
Given 'utf8' encoding is specified, and a large enough input file,
fs.ReadFile
will throw an asynchronous error.Example program
Input: 268 megabytes of data
Success.
Input: 269 megabytes of data
No Success.
Worse, the error isn't forwarded to the callback – the process is throwing asynchronously.
The error is not something specific to
fs.readFile
though, the same error is produced if wetoString
on the buffer directly, without the 'utf8' parameter, unsurprisingly. The problem is the uncatchable throw.While perhaps the throw in the
Buffer.prototype.toString
makes sense:node/lib/buffer.js
Lines 352 to 361 in f8152df
It does seem like poor behaviour to have uncatchable errors being thrown in core APIs where the user has explicitly attached an errback.
Would a
try…catch
around thebuffer = buffer.toString(context.encoding);
infs.ReadFile
be appropriate?node/lib/fs.js
Lines 377 to 378 in f8152df
fs.readFile
is understandably hot code, I haven't done benchmarking on the impact of atry…catch
here.Given that there appears to be an upper limit to what can be stringified safely, perhaps the max length could be tested for before attempting the stringification, and a 'this is too big' Error would ideally pop out of the callback.
Suggest at a minimum a more helpful error message "our buffering is good but have you tried the streams?"
The text was updated successfully, but these errors were encountered: