original.roland
original.roland

Reputation: 700

Node read only first N bytes/chars from file

I'm coding an app which has to determine a limited set of file types. These are all text based, and the marker I'm looking for should be at the beginning N bytes, let's say 512 bytes. The way how I determine the type afterwards is not subject of the current topic.

I've seen fs.readFile/Sync(), but it reads the whole file, which is unnecessary in my case. Is it possible to read only a few bytes from the beginning to improve performance?

I'm using typescript, but I don't think it matters in the current case. Also, I'm looking for something that doesn't involve executing random stuffs from the main OS (eg cat or echo with some special parameters)

Upvotes: 1

Views: 270

Answers (0)

Related Questions