Just playing a bit with the concept of using FinalizationRegistry to detect when/if the user has forgotten to properly release a resource and print a corresponding warning?
Something like:
const fsStreamRegistery = new FinalizationRegistry(state => {
if (!state.destroyed) {
process.warning('file stream leak')
}
})
function createReadStream(...) {
const stream = new ReadStream(...)
fsStreamRegistery.register(stream, stream._readableState)
return stream
}
Potential candidates:
net.Socket
fs.FileHandle
fs.WriteStream
fs.ReadStream