-
-
Notifications
You must be signed in to change notification settings - Fork 343
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
Why is detecting file type from buffer async? #410
Comments
Because the core parser is made with a stream which is async. It would indeed be nice to have synchronous support too. |
Indeed, due to the common functions and code which, depending under the underlying media, require asynchronous behavior. it not feasible to split these into asynchronous and synchronous. Unfortunately there is no way, or at least as far as I know, to convert asynchronous into synchronous behavior. Is the asynchronous an issue, knowing it resolves immediate? |
Thank you for the explanation.
In some cases yes. As an example transaction function from better-sqlite3 needs a synchronous callback, I believe it won't work for async callbacks even if it resolves immediately. Of course there are workarounds possible, but they often result in more complex code. But I understand the engineering challenges in making this call synchronous. |
I didn't directly thought about such a case. In case of a transaction, you don''t want to introduce any unnecessary delay. Even if there an expensive synchronous function is probably better to execute outside the transaction. Nevertheless, I understand it maybe bit inconvenient some cases. |
Hi, I'm wondering why is
FileType.fromBuffer(buffer)
async - i.e. returns Promise?Reading buffer seems naturally synchronous since there's no I/O involved.
The text was updated successfully, but these errors were encountered: