diff options
| author | Omar Rizwan <omar@omar.website> | 2020-12-18 23:54:36 -0800 | 
|---|---|---|
| committer | Omar Rizwan <omar@omar.website> | 2020-12-18 23:54:36 -0800 | 
| commit | bb0376c407f0745e5bfc5c4d88fd5bc0a40a7d33 (patch) | |
| tree | 8c6db4ed58ee839eb281e6687503789a9e0bcbf9 /extension | |
| parent | d21c9eace16593446cdedbd85ba780b7f4368b70 (diff) | |
checkpoint: starting work on truncate. more README stubs.
Diffstat (limited to 'extension')
| -rw-r--r-- | extension/background.js | 17 | 
1 files changed, 15 insertions, 2 deletions
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 => {  | 
