From 6f10deede459bae8aebd4efb38732c58b97fd873 Mon Sep 17 00:00:00 2001 From: MrWhitee <20826721+MrWhitee4@users.noreply.github.com> Date: Sat, 6 Jun 2026 14:39:31 +0200 Subject: [PATCH 1/2] fix: silence Node DEP0005 by patching formidable's Buffer() calls The bundled formidable 1.2.2 (via koa-body 4) still uses the deprecated Buffer() constructor in MultipartParser.initWithBoundary and the base64 part decoder, so Node logs DEP0005 on every screenshot upload. formidable 1.x never moved to the safe Buffer APIs, and the versions that did (formidable 2/3) need koa-body 5/6 and webpack 5, which FiveM's webpack-4 builder cannot compile. So the fix stays on formidable 1.x and patches the four calls through patch-package, reapplied on postinstall: - new Buffer(n) -> Buffer.alloc(n) (boundary, lookbehind) - new Buffer(str,'base64') -> Buffer.from(...) (base64 decode, x2) --- .gitattributes | 2 ++ CHANGELOG.md | 23 ++++++++++++++++++++++ package.json | 9 +++++++-- patches/formidable+1.2.2.patch | 36 ++++++++++++++++++++++++++++++++++ 4 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 .gitattributes create mode 100644 CHANGELOG.md create mode 100644 patches/formidable+1.2.2.patch diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..13a090c --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Keep patch-package patches byte-stable across platforms (no CRLF conversion) +patches/**/*.patch -text diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..3557b98 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,23 @@ +# Changelog + +Maintained fork of screenshot-basic. + +## Unreleased + +### Fixed +- Node logged a DEP0005 deprecation warning on every screenshot upload. The + bundled `formidable@1.2.2` (pulled in by `koa-body@4`) still called the old + `Buffer()` constructor in `MultipartParser.initWithBoundary` and the base64 + part decoder. + + formidable 1.x never moved to the safe Buffer APIs, and the versions that did + (formidable 2/3) need koa-body 5/6 and webpack 5, which FiveM's bundled + webpack 4 cannot compile. So the fix stays on formidable 1.x and patches the + four calls through `patch-package`, reapplied on `postinstall`: + - `new Buffer(n)` to `Buffer.alloc(n)` (boundary and lookbehind) + - `new Buffer(str, 'base64')` to `Buffer.from(str, 'base64')` (two base64 decodes) + + No runtime change: the boundary buffer is fully written before use, and the + base64 calls take strings, never the uninitialized-number form. + +Author: MrWhitee diff --git a/package.json b/package.json index 122b6f8..5fde81d 100644 --- a/package.json +++ b/package.json @@ -4,10 +4,15 @@ "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": "", + "author": "MrWhitee", "license": "MIT", + "devDependencies": { + "patch-package": "^8.0.0", + "postinstall-postinstall": "^2.1.0" + }, "dependencies": { "@citizenfx/client": "^1.0.3404-1", "@citizenfx/http-wrapper": "^0.2.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 = {}; From c2b2d66dc89913c785827be641bbc56da409a3ed Mon Sep 17 00:00:00 2001 From: MrWhitee <20826721+MrWhitee4@users.noreply.github.com> Date: Sat, 6 Jun 2026 14:45:50 +0200 Subject: [PATCH 2/2] Remove author field from package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5fde81d..9624e63 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "test": "echo \"Error: no test specified\" && exit 1", "postinstall": "patch-package" }, - "author": "MrWhitee", + "author": "", "license": "MIT", "devDependencies": { "patch-package": "^8.0.0",