Normally I'd say "copy the table contents manually", but since you really just want to overwrite fs.open() (not the whole API), instead of:
local _fs = fs
... you'd want to do something like:
local _fsopen = fs.open
While we're at it, you could also do away with that "for" loop. Instead, check to see what specific functions exist within your handle, then rewrite based on those:
if handler.write and handler.writeLine then
-- Text output.
elseif handler.write then
-- Binary output.
elseif handler.read then
-- Binary input.
else
-- Text input.
end
Append mode makes matters more difficult. The simple way to deal with it is to spot it BEFORE you open your file handle for output, manually read in the existing file content first, decode it, get whatever the user wants to add to it, then finally re-encode the whole stream and write the lot to disk when a request to close the handle comes through.