Exercise: The Lazy Buffer
Practice how to create a factory function that generates a virtual proxy for a buffer.
We'll cover the following
Problem statement
Can you implement a createLazyBuffer(size)
named factory function that generates a virtual proxy for a buffer (Buffer
) of the given size? The proxy instance should instantiate a Buffer
object (effectively allocating the given amount of memory) only when write()
is being invoked for the first time. If no attempt to write into the buffer is made, no Buffer
instance should be created.
Coding challenge
Write your solution code in the following code widget. We’ve already added the package.json
file for your ease.
Get hands-on with 1400+ tech skills courses.