diff --git a/README.md b/README.md index cffb2dd..f414651 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,25 @@ # screenshot-basic for FiveM +> **Patched fork — DeprecationWarning [DEP0005]** +> +> The `formidable@1.2.2` dependency (pulled in by `koa-body`, used to parse +> multipart uploads on the server side) uses the old `new Buffer()` constructor, +> which emits `(node) [DEP0005] DeprecationWarning: Buffer() is deprecated` +> on every screenshot upload. It is harmless, but it clutters the logs. +> +> Because the faulty code is in a **dependency** (`node_modules/`, regenerated +> on every `yarn install`), it cannot be permanently fixed “in place”. This +> fork therefore uses **[patch-package](https://github.com/ds300/patch-package)**: +> +> - `patches/formidable+1.2.2.patch` replaces `new Buffer(n)` → `Buffer.alloc(n)` +> and `new Buffer(str, 'base64')` → `Buffer.from(str, 'base64')`. +> - The `"postinstall": "patch-package"` hook (in `package.json`) **automatically +> reapplies** the patch after each `yarn install` / `npm install`, so it +> survives reinstalls and rebuilds (webpack then bundles the patched +> formidable → no more warning). +> +> Nothing else about the original behavior is changed. + ## Description screenshot-basic is a basic resource for making screenshots of clients' game render targets using FiveM. It uses the same backing diff --git a/package.json b/package.json index 122b6f8..eb49298 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,8 @@ "description": "", "main": "index.js", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "postinstall": "patch-package" }, "author": "", "license": "MIT", @@ -23,6 +24,8 @@ "koa-body": "^4.0.6", "koa-router": "^7.4.0", "mv": "^2.1.1", + "patch-package": "^8.0.1", + "postinstall-postinstall": "^2.1.0", "ts-loader": "^5.3.3", "typescript": "3.2.2", "uuid": "^3.3.2", diff --git a/patches/formidable+1.2.2.patch b/patches/formidable+1.2.2.patch new file mode 100644 index 0000000..6dee70e --- /dev/null +++ b/patches/formidable+1.2.2.patch @@ -0,0 +1,36 @@ +diff --git a/node_modules/formidable/lib/incoming_form.js b/node_modules/formidable/lib/incoming_form.js +index dbd920b..4e8c962 100644 +--- a/node_modules/formidable/lib/incoming_form.js ++++ b/node_modules/formidable/lib/incoming_form.js +@@ -403,12 +403,12 @@ IncomingForm.prototype._initMultipart = function(boundary) { + can be divided vy 3. + */ + var offset = parseInt(part.transferBuffer.length / 4, 10) * 4; +- part.emit('data', new Buffer(part.transferBuffer.substring(0, offset), 'base64')); ++ part.emit('data', Buffer.from(part.transferBuffer.substring(0, offset), 'base64')); + part.transferBuffer = part.transferBuffer.substring(offset); + }; + + parser.onPartEnd = function() { +- part.emit('data', new Buffer(part.transferBuffer, 'base64')); ++ part.emit('data', Buffer.from(part.transferBuffer, 'base64')); + part.emit('end'); + }; + break; +diff --git a/node_modules/formidable/lib/multipart_parser.js b/node_modules/formidable/lib/multipart_parser.js +index 36de2b0..071d205 100644 +--- a/node_modules/formidable/lib/multipart_parser.js ++++ b/node_modules/formidable/lib/multipart_parser.js +@@ -57,10 +57,10 @@ MultipartParser.stateToString = function(stateNumber) { + }; + + MultipartParser.prototype.initWithBoundary = function(str) { +- this.boundary = new Buffer(str.length+4); ++ this.boundary = Buffer.alloc(str.length+4); + this.boundary.write('\r\n--', 0); + this.boundary.write(str, 4); +- this.lookbehind = new Buffer(this.boundary.length+8); ++ this.lookbehind = Buffer.alloc(this.boundary.length+8); + this.state = S.START; + + this.boundaryChars = {};