-
-
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
Use tokenizer #262
Use tokenizer #262
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other than nitpick, these changes are looking good.
index.d.ts
Outdated
/** | ||
Detect the file type of a `Buffer`/`Uint8Array`/`ArrayBuffer`. The file type is detected by checking the [magic number](https://en.wikipedia.org/wiki/Magic_number_(programming)#Magic_numbers_in_files) of the buffer. | ||
Detect the file type of a `Buffer`/`Uint8Array`/`ArrayBuffer`. | ||
The file type is detected by checking the [magic number](https://en.wikipedia.org/wiki/Magic_number_(programming)#Magic_numbers_in_files) of the buffer. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't do unrelated changes.
@@ -64,7 +64,6 @@ const names = { | |||
], | |||
mp3: [ | |||
'fixture', | |||
'fixture-offset1-id3', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was this fixture removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed this fixture because I don't think it is a realistic representation of an MP3 file:
- It is not normal an ID3 header starts at offset 1 or any other arbitrary offset in combination with an MPEG stream.
- Common tools like Mp3Tag or Foobar2000, and a low level MPEG frame decoder I use, cannot make any sense of this file (neither from the MPEG frames).
I am not sure if it was this file, or another file from the same source, even the extension appeared to be wrong. This kind of fixtures are just causing confusion.
get: (buf, off) => { | ||
return (buf[off + 3] & 0x7F) | ((buf[off + 2]) << 7) | ((buf[off + 1]) << 14) | ((buf[off]) << 21); | ||
}, | ||
len: 4 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
len: 4 | |
length: 4 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, this part if the token interface.
Cannot do that, will break the token.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright. No worries. Although, I would recommend taking a look at https://github.com/sindresorhus/eslint-plugin-unicorn/blob/master/docs/rules/prevent-abbreviations.md It really makes code more readable to not use abbreviations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, despite the fact I cheat sometimes for good or bad reasons. I am firm believer in readable code. If that takes a bit more text that is fine. There are other ways to optimize, if that is the reason to deviate from writing verbose code. Easily being able to understand what is going on is one of them.
I did not design the token interface btw, I inherited it via strtok2 (which I own and maintained and extended, but I did not write it initially). I wrote strtok3 replacing the events with promises which allowed the tokens to be typed. The tokens remained intact.
…, fromBuffer, fromFile.
…, fromBuffer, fromFile.
Improve sub-type parsing of PNG, matroska & ZIP file types
Remove ID3 header starting at offset 1 fixture.
Sorted function by signature length.
*/ | ||
readonly mimeTypes: fileType.MimeType; | ||
*/ | ||
const mimeTypes: fileType.MimeType; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: eff47af
Thanks a lot for merging @sindresorhus, allows to move on. |
Implementation of Change proposal: break the fixed sample limit #248:
Migrating most file detection to tokenizer
Improved parsing using tokenizer of:
As this involves significant effort, it would be good to hear your are happy with approach you would like me to take @sindresorhus.