Commit d5770df
fix: avoid using deprecated Buffer constructor (#94)
* fix: avoid using deprecated Buffer constructor
Buffer.alloc() is supported on Node.js >= 4.5.0, and allocates a zero-filled
buffer on all supported versions.
This solves two issues:
* Buffer() constructor (aka 'new Buffer()') is deprecated, so avoid using it
* On 4.x and 6.x, Buffer(number) is not zero-filled, so this code was
allocating an uninitialized Buffer when file length was less than 150, so
the behaviour of readShebang() was actually undefined in that case (as in
could have returned anything, depending on the uninitialized memory chunk).
Refs: https://nodejs.org/api/deprecations.html#deprecations_dep0005_buffer_constructor
* readShebang: name reused inline constant
'150' was used two times, it deserves a name.
It's the size of the pre-read buffer.
* readShebang: Buffer API compat for old Node.js
To be reverted when dropping outdated Node.js versions support.1 parent 6b64987 commit d5770df
1 file changed
+13
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
8 | 20 | | |
9 | | - | |
10 | 21 | | |
11 | 22 | | |
12 | 23 | | |
13 | | - | |
| 24 | + | |
14 | 25 | | |
15 | 26 | | |
16 | 27 | | |
| |||
0 commit comments