Skip to content

Commit

Permalink
Use Buffer.allocUnsafe instead of the deprecated new Buffer() (palant…
Browse files Browse the repository at this point in the history
…ir#3985)

(node:16148) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
allocUnsafe should be fine because in both cases, the buffer is immediately filled and thrown out.
  • Loading branch information
NaridaL authored and giladgray committed Jun 26, 2018
1 parent 46098f7 commit c01bb2c
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/rules/encodingRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function showEncoding(encoding: Encoding): string {
function detectEncoding(fileName: string): Encoding {
const fd = fs.openSync(fileName, "r");
const maxBytesRead = 3; // Only need 3 bytes to detect the encoding.
const buffer = new Buffer(maxBytesRead);
const buffer = Buffer.allocUnsafe(maxBytesRead);
const bytesRead = fs.readSync(fd, buffer, /*offset*/ 0, /*length*/ maxBytesRead, /*position*/ 0);
fs.closeSync(fd);
return detectBufferEncoding(buffer, bytesRead);
Expand Down
2 changes: 1 addition & 1 deletion src/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ async function tryReadFile(filename: string, logger: Logger): Promise<string | u
if (!fs.existsSync(filename)) {
throw new FatalError(`Unable to open file: ${filename}`);
}
const buffer = new Buffer(256);
const buffer = Buffer.allocUnsafe(256);
const fd = fs.openSync(filename, "r");
try {
fs.readSync(fd, buffer, 0, 256, 0);
Expand Down

0 comments on commit c01bb2c

Please sign in to comment.