Skip to content
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

[QUESTION]: form-data vs formdata-node #1

Closed
xr0master opened this issue Feb 5, 2019 · 6 comments
Closed

[QUESTION]: form-data vs formdata-node #1

xr0master opened this issue Feb 5, 2019 · 6 comments

Comments

@xr0master
Copy link

Hey guys. Can you explain your motivation to create this project, please?
What is different between form-data and formdata-node?

Thank you

@octet-stream
Copy link
Owner

octet-stream commented Feb 5, 2019

Hello. That's a good question. In short: I decided to implement FormData other way and drop old Node.js versions.

Initially this project was just my experiment with Node.js streams and was made because of these reasons:

  • form-data support old versions of Node.js, starting from v0.12. formdata-node support Node.js 8 and higher
  • form-data currently support only .append() method from the API: Strive for symmetrical API to browsers FormData. form-data/form-data#124 (I mean, look at this issue, it's unresolved for few years). formdata-node supports .append(), .set(), .get(), .getAll(), .has(), .delete(), .forEach(), .keys(), .values(), .entries() and .[Symbol.iterator] so you can use (in about) full implementation of the FormData in your Node.js projects, for tests or something else.
  • formdata-node uses asynchronous iterators to read the data passed to internal storage. I'm also using different way to store everything you pass into FormData instance: all the data will be stored as-is until you start to read FormData#stream or FormData#[Symbol.asyncIterator] It allows both read and write each field in FormData.

@xr0master
Copy link
Author

Thank you very much for such a detailed response.

I see that the packet size is pretty much the same.
What about benchmark versus competitor?
And CPU load due to while(true)?

You know, when a server has more than half a million requests, each optimization has its own price. So it is very important for me.

PS I'll be happy to have a typescript definition file as TS fanboy :)
PPS And again thank you for your amazing job!

@octet-stream
Copy link
Owner

octet-stream commented Feb 5, 2019

I understand your point, but to be honest, I never thought about benchmarking in this project since this was an experiment. I'm also never wrote benchmarks, so I don't know how it works with a lots of data. Sorry about that :)
By the way, I think we might don't need while(true) in FormData#__getField since it is the asynchronous iterator. But StreamIterator still needs infinite loop to read the data from Read/Readable streams. At least I don't know other way to make it works. Maybe this project needs some refactoring :)

I thought you can use standard definitions of the FormData in TS, so I didn't added them here. But if it doesn't work, I think we can fix that :)
Honestly, I barely familiar with TS, but I think we can jus get standard definitions and extend them with formdata-node specific things.

I'm also don't support any way to get size of the FormData, but I'm planning this feature for next releases.

@octet-stream
Copy link
Owner

Oh, I just realised that browser implementation uses different data types for FormData entry values, which means that you can't use it here :D
Sure I will add typings file. I guess I figured out how it could be made. Is there a way to test .d.ts files? Just to be sure if I'm working in the right direction since I'm barely familiar with TS.

@octet-stream
Copy link
Owner

I'm closing this thread because of inactivity.

TS typings will be added if only I'd learn TS or somebody help me with that.

@octet-stream
Copy link
Owner

octet-stream commented Jun 13, 2019

@xr0master hey 👋
I've added some typings to use the library with TS. You can try it in 1.7.0 version. Please, let me know if you have any issue with them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants