-
-
Notifications
You must be signed in to change notification settings - Fork 37.1k
Feature: Immutable Buffer buffer.readonly() #27080
Copy link
Copy link
Closed as not planned
Labels
bufferIssues and PRs related to the buffer subsystem.Issues and PRs related to the buffer subsystem.feature requestIssues requesting new Node.js features.Issues requesting new Node.js features.never-staleIssues and PRs exempt from automated stale handling.Issues and PRs exempt from automated stale handling.staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.Issues and PRs marked stale due to inactivity and scheduled for automatic closure.
Description
Activity
Metadata
Metadata
Assignees
Labels
bufferIssues and PRs related to the buffer subsystem.Issues and PRs related to the buffer subsystem.feature requestIssues requesting new Node.js features.Issues requesting new Node.js features.never-staleIssues and PRs exempt from automated stale handling.Issues and PRs exempt from automated stale handling.staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.Issues and PRs marked stale due to inactivity and scheduled for automatic closure.
Is your feature request related to a problem? Please describe.
I have an object with a buffer attached and I need to be able to pass around that Buffer but ensure that it won’t mutate.
Describe the solution you'd like
A method on Buffer instances to put it into a “read only mode” would be ideal. I’d prefer it not be in the constructor so that I don’t have to perform a memcopy in order to get it.
Describe alternatives you've considered
There isn’t much you can do except force a full copy every time you pass it around, which is pretty bad. Object.freeze() won’t work because all the mutations happen through methods that are effectively invisible to Object.freeze().
However, Object.freeze() has some negative performance implications while implementing this in the Buffer object itself would not have the same problems. This would be a nice features of Node.js Core.