{"record":{"id":"ef77e71969e7716a","repo":"amark/gun","slug":"new-safebuffer-is-depreciated-please-use-safebu","errorCode":null,"errorMessage":"new SafeBuffer() is depreciated, please use SafeBuffer.from()","messagePattern":"new SafeBuffer\\(\\) is depreciated, please use SafeBuffer\\.from\\(\\)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"sea/buffer.js","lineNumber":11,"sourceCode":";(function(){\n\n    require('./base64');\n    // This is Buffer implementation used in SEA. Functionality is mostly\n    // compatible with NodeJS 'safe-buffer' and is used for encoding conversions\n    // between binary and 'hex' | 'utf8' | 'base64'\n    // See documentation and validation for safe implementation in:\n    // https://github.com/feross/safe-buffer#update\n    var SeaArray = require('./array');\n    function SafeBuffer(...props) {\n      console.warn('new SafeBuffer() is depreciated, please use SafeBuffer.from()')\n      return SafeBuffer.from(...props)\n    }\n    SafeBuffer.prototype = Object.create(Array.prototype)\n    Object.assign(SafeBuffer, {\n      // (data, enc) where typeof data === 'string' then enc === 'utf8'|'hex'|'base64'\n      from() {\n        if (!Object.keys(arguments).length || arguments[0]==null) {\n          throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.')\n        }\n        const input = arguments[0]\n        let buf\n        if (typeof input === 'string') {\n          const enc = arguments[1] || 'utf8'\n          if (enc === 'hex') {\n            const bytes = input.match(/([\\da-fA-F]{2})/g)\n            .map((byte) => parseInt(byte, 16))\n            if (!bytes || !bytes.length) {\n              throw new TypeError('Invalid first argument for type \\'hex\\'.')","sourceCodeStart":1,"sourceCodeEnd":29,"githubUrl":"https://github.com/amark/gun/blob/552227599d47ba0493824b7fcf8a00c8cd6404ba/sea/buffer.js#L1-L29","documentation":"This is not a thrown error but a console.warn emitted by SEA's SafeBuffer constructor in sea/buffer.js. The SafeBuffer constructor is kept only for API compatibility with Node's 'safe-buffer' package; calling it with `new SafeBuffer(...)` (or as a plain function) logs this deprecation notice and transparently delegates to SafeBuffer.from(...), so behavior still works but is discouraged. The message intentionally mirrors the feross/safe-buffer update where constructor calls were replaced by static from()/alloc() methods.","triggerScenarios":"Calling `new SafeBuffer(data, enc)` or `SafeBuffer(...)` anywhere in code using Gun's SEA module instead of `SafeBuffer.from(data, enc)`; typically in crypto helpers converting between binary and hex/utf8/base64. Also triggered by code copied from older Node Buffer-style usage patterns.","commonSituations":"Developers porting Node code that uses `new Buffer(...)` semantics to browser SEA code; older third-party snippets or plugins written against early SEA versions; accidental search-and-replace of Buffer with SafeBuffer keeping the `new` keyword.","solutions":["Replace `new SafeBuffer(...)` with `SafeBuffer.from(...)` using the same arguments (e.g. SafeBuffer.from(str,'utf8')).","Use SafeBuffer.alloc(len) when you need a zero-filled buffer of a given length instead of constructing one.","Grep the project for `new SafeBuffer` and fix all occurrences; the constructor path may be removed in future SEA versions.","If this warning comes from a dependency, update that dependency to a SEA version using the from() API."],"exampleFix":"// before\\nvar buf = new SafeBuffer('hello', 'utf8');\\n// after\\nvar buf = SafeBuffer.from('hello', 'utf8');","handlingStrategy":"fallback","validationCode":"// Prefer the supported API surface\\nif (typeof SafeBuffer.from !== 'function') throw new Error('SEA SafeBuffer.from unavailable');\\n// Use SafeBuffer.from(data, enc) instead of new SafeBuffer(data, enc)\\nvar buf = SafeBuffer.from('hello', 'utf8');","typeGuard":"function isSeaBuffer(x){ return x instanceof SafeBuffer || (Array.isArray(x) && typeof x.toString === 'function' && x.constructor && /SeaArray|SafeBuffer/.test(String(x.constructor.name))); }","tryCatchPattern":"try {\\n  var buf = SafeBuffer.from(input, 'utf8');\\n} catch (e) {\\n  // SafeBuffer.from throws TypeError on null/invalid input\\n  console.error('SEA buffer conversion failed:', e.message);\\n}","preventionTips":["Never call `new SafeBuffer(...)`; always use SafeBuffer.from(data, enc) or SafeBuffer.alloc(len).","Treat the console.warn as a signal to update code before the constructor path is removed.","Encode explicit encodings ('utf8'|'hex'|'base64') rather than relying on defaults.","Grep CI for /new\\\\s+SafeBuffer/ to catch regressions."],"tags":["deprecation","nodejs","buffer","crypto","sea"],"backgroundTag":"deprecated-constructor-usage","analyzedSha":"552227599d47ba0493824b7fcf8a00c8cd6404ba","analyzedAt":"2026-09-02T18:40:58.370Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T21:17:11.164Z"}