From 3fdfc102e84985852a3cb2cc79e0640962e107fd Mon Sep 17 00:00:00 2001 From: Matthew Pietz Date: Fri, 17 Apr 2020 10:32:37 -0700 Subject: [PATCH] Fix deprecation warning For environments which support `Buffer.allocUnsafe()`, use it instead. https://nodejs.org/en/docs/guides/buffer-constructor-deprecation/ --- server.coffee | 3 ++- server.js | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/server.coffee b/server.coffee index 2af6f6f..2f7313b 100644 --- a/server.coffee +++ b/server.coffee @@ -194,7 +194,8 @@ process_url = (url, transferredHeaders, resp, remaining_redirects) -> # decode a string of two char hex digits hexdec = (str) -> if str and str.length > 0 and str.length % 2 == 0 and not str.match(/[^0-9a-f]/) - buf = new Buffer(str.length / 2) + size = str.length / 2 + buf = if Buffer.allocUnsafe then Buffer.allocUnsafe(size) else new Buffer(size) for i in [0...str.length] by 2 buf[i/2] = parseInt(str[i..i+1], 16) buf.toString() diff --git a/server.js b/server.js index 27621b9..4d595fd 100644 --- a/server.js +++ b/server.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 1.12.6 +// Generated by CoffeeScript 1.12.7 (function() { var Crypto, Fs, Http, Https, Path, QueryString, Url, accepted_image_mime_types, camo_hostname, content_length_limit, current_connections, debug_log, default_security_headers, error_log, finish, four_oh_four, hexdec, keep_alive, logging_enabled, max_redirects, port, process_url, server, shared_key, socket_timeout, started_at, total_connections, version, indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; @@ -229,9 +229,10 @@ }; hexdec = function(str) { - var buf, i, j, ref; + var buf, i, j, ref, size; if (str && str.length > 0 && str.length % 2 === 0 && !str.match(/[^0-9a-f]/)) { - buf = new Buffer(str.length / 2); + size = str.length / 2; + buf = Buffer.allocUnsafe ? Buffer.allocUnsafe(size) : new Buffer(size); for (i = j = 0, ref = str.length; j < ref; i = j += 2) { buf[i / 2] = parseInt(str.slice(i, +(i + 1) + 1 || 9e9), 16); }