diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md index 5d036fa2917ce8..c2de5e297a5390 100644 --- a/doc/api/deprecations.md +++ b/doc/api/deprecations.md @@ -695,6 +695,9 @@ Type: End-of-Life -Type: Documentation-only +Type: Runtime The [`SlowBuffer`][] class is deprecated. Please use [`Buffer.allocUnsafeSlow(size)`][] instead. diff --git a/lib/buffer.js b/lib/buffer.js index 756657e910893e..88625299bced5e 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -88,6 +88,7 @@ const { kIsEncodingSymbol, defineLazyProperties, encodingsMap, + deprecate, } = require('internal/util'); const { isAnyArrayBuffer, @@ -1322,7 +1323,10 @@ function isAscii(input) { module.exports = { Buffer, - SlowBuffer, + SlowBuffer: deprecate( + SlowBuffer, + 'SlowBuffer() is deprecated. Please use Buffer.allocUnsafeSlow()', + 'DEP0030'), transcode, isUtf8, isAscii, diff --git a/test/parallel/test-buffer-slow.js b/test/parallel/test-buffer-slow.js index 07138d5db0b397..0d89491cfbd155 100644 --- a/test/parallel/test-buffer-slow.js +++ b/test/parallel/test-buffer-slow.js @@ -1,12 +1,18 @@ 'use strict'; -require('../common'); +const common = require('../common'); const assert = require('assert'); const buffer = require('buffer'); const SlowBuffer = buffer.SlowBuffer; const ones = [1, 1, 1, 1]; +common.expectWarning( + 'DeprecationWarning', + 'SlowBuffer() is deprecated. Please use Buffer.allocUnsafeSlow()', + 'DEP0030' +); + // Should create a Buffer let sb = SlowBuffer(4); assert(sb instanceof Buffer);