From bb0376c407f0745e5bfc5c4d88fd5bc0a40a7d33 Mon Sep 17 00:00:00 2001 From: Omar Rizwan Date: Fri, 18 Dec 2020 23:54:36 -0800 Subject: checkpoint: starting work on truncate. more README stubs. --- extension/background.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'extension') diff --git a/extension/background.js b/extension/background.js index e92069e..18848d7 100644 --- a/extension/background.js +++ b/extension/background.js @@ -142,15 +142,25 @@ const defineFile = (getData, setData) => ({ st_size: toArray(await getData(path)).length }; }, + async open({path}) { return { fh: Cache.storeObject(toArray(await getData(path))) }; }, async read({path, fh, size, offset}) { return { buf: String.fromCharCode(...Cache.getObjectForHandle(fh).slice(offset, offset + size)) } }, async write({path, buf}) { // FIXME: patch + // I guess caller should override write() if they want to actually + // patch and not just re-set the whole string (for example, + // if they want to hot-reload just one function the user modified) setData(path, buf); return { size: utf8(buf).length }; }, - async release({fh}) { Cache.removeObjectForHandle(fh); return {}; } + async release({fh}) { Cache.removeObjectForHandle(fh); return {}; }, + + async truncate({path, size}) { + // TODO: weird case if they truncate while the file is open + // (but `echo hi > foo.txt` uses O_TRUNC which doesn't do that) + setData(path, (await getData(path)).truncate(size)); return {}; + } }); router["/tabs/by-id"] = { @@ -169,12 +179,15 @@ router["/tabs/by-id"] = { // TODO: mem (?) // TODO: cpu (?) +// TODO: dom/ ? +// TODO: globals/ ? + // screenshot.png (FIXME: how to keep from blocking when unfocused?) // TODO: archive.mhtml ? // TODO: printed.pdf // control // resources/ -// TODO: scripts/ +// TODO: scripts/ TODO: allow creation, eval immediately (function() { const withTab = (readHandler, writeHandler) => defineFile(async path => { -- cgit v1.2.3