This codemod migrates deprecated SlowBuffer usage to Buffer.allocUnsafeSlow() to handle Node.js DEP0030.
What It Does
This codemod transforms:
SlowBuffer constructor calls to Buffer.allocUnsafeSlow()
- Direct
SlowBuffer calls to Buffer.allocUnsafeSlow()
- Import/require statements to use
Buffer instead of SlowBuffer
Before/After
Before:import { SlowBuffer } from "buffer";
const buf = new SlowBuffer(1024);
After:import { Buffer } from "buffer";
const buf = Buffer.allocUnsafeSlow(1024);
Before:const { SlowBuffer } = require("buffer");
const buf = new SlowBuffer(1024);
After:const { Buffer } = require("buffer");
const buf = Buffer.allocUnsafeSlow(1024);
The SlowBuffer constructor was deprecated in Node.js v6.0.0 and removed in later versions. This migration is essential for maintaining compatibility with modern Node.js versions.
Usage
Run this codemod on your project:
npx codemod node/userland/slow-buffer-to-buffer-alloc-unsafe-slow
Buffer.allocUnsafeSlow() creates a buffer outside the shared internal memory pool. Use this when you need a buffer that won’t be pooled, but remember that the buffer contents are uninitialized and may contain sensitive data.