node-argon2 icon indicating copy to clipboard operation
node-argon2 copied to clipboard

Feat request: synchronous version

Open euberdeveloper opened this issue 1 year ago • 5 comments

Why not having a synchronous version of the functions to hash and verify? Bcrypt for example has it and in some niche cases it could be helpful.

euberdeveloper avatar Jan 27 '24 13:01 euberdeveloper

What's the niche use case you have in mind?

ranisalt avatar Jan 27 '24 22:01 ranisalt

Something like this https://stackoverflow.com/a/64200074

Also I don't see why someone couldn't be able to choose a synchronous function

euberdeveloper avatar Jan 28 '24 00:01 euberdeveloper

Also I don't see why someone couldn't be able to choose a synchronous function

It's a matter of maintaining extra code in order to support a scenario that hasn't really happened in the past years. Even the native Node modules now have a promises version (i.e. fs/promises and readline/promises)

You can use deasync if you really want use synchronous calls, though I highly recommend against

ranisalt avatar Jan 29 '24 15:01 ranisalt

I don't see a relation between the promises version of fs and having a synchronous version for this library.

The promises thing has been introduced because otherwise it would have worked with the ugly old-style callbacks and one would have had to create promises to be able to use async/await Actually the fact that there are sync. versions for most of the functions (such as readdirSync) and the fact that exists has been deprecated in favour of existsSync would suggest the opposite.

Still, I understand if you don't want to have more code to maintain

euberdeveloper avatar Jan 29 '24 19:01 euberdeveloper

Yup, that is the major issue. Maintaining a single path has helped keep the library short and simple. It has been requested sporadically in the past #136 #254 #267 and 2 out of 3 times it was lack of information about promises

In the case that it was actually a limitation, I suggested deasync, which ends up being a good solution as you'll likely have to handle other async dependencies in your code. So I consider it a win-win 😉

the fact that exists has been deprecated in favour of existsSync would suggest the opposite

That's not the case though. It has been superseded by stat or access and the removal has more to do with the fact there is a race condition when checking if a file exists prior to operating with it, so it's better to just try the operation and catch the error

ranisalt avatar Jan 30 '24 15:01 ranisalt