mirror of
https://github.com/osnr/TabFS.git
synced 2024-05-17 21:16:35 +02:00
Manually set getattr op. Fixes text file.
This commit is contained in:
parent
76efd118e0
commit
f576b4c324
|
@ -44,6 +44,17 @@ function pathComponent(path, i) {
|
||||||
function sanitize(s) {
|
function sanitize(s) {
|
||||||
return s.replace(/[^A-Za-z0-9_\-\.]/gm, '_');
|
return s.replace(/[^A-Za-z0-9_\-\.]/gm, '_');
|
||||||
}
|
}
|
||||||
|
function stringSize(str) {
|
||||||
|
// returns the byte length of an utf8 string
|
||||||
|
var s = str.length;
|
||||||
|
for (var i=str.length-1; i>=0; i--) {
|
||||||
|
var code = str.charCodeAt(i);
|
||||||
|
if (code > 0x7f && code <= 0x7ff) s++;
|
||||||
|
else if (code > 0x7ff && code <= 0xffff) s+=2;
|
||||||
|
if (code >= 0xDC00 && code <= 0xDFFF) i--; //trail surrogate
|
||||||
|
}
|
||||||
|
return s + 1;
|
||||||
|
}
|
||||||
|
|
||||||
/* if I could specify a custom editor interface for all the routing
|
/* if I could specify a custom editor interface for all the routing
|
||||||
below ... I would highlight the route names in blocks of some color
|
below ... I would highlight the route names in blocks of some color
|
||||||
|
@ -53,6 +64,14 @@ const router = {};
|
||||||
|
|
||||||
function withTab(handler) {
|
function withTab(handler) {
|
||||||
return {
|
return {
|
||||||
|
async getattr(path) {
|
||||||
|
const tab = await browser.tabs.get(parseInt(pathComponent(path, -2)));
|
||||||
|
return {
|
||||||
|
st_mode: unix.S_IFREG | 0444,
|
||||||
|
st_nlink: 1,
|
||||||
|
st_size: stringSize(handler(tab))
|
||||||
|
};
|
||||||
|
},
|
||||||
async read(path, fh, size, offset) {
|
async read(path, fh, size, offset) {
|
||||||
const tab = await browser.tabs.get(parseInt(pathComponent(path, -2)));
|
const tab = await browser.tabs.get(parseInt(pathComponent(path, -2)));
|
||||||
return handler(tab).substr(offset, size);
|
return handler(tab).substr(offset, size);
|
||||||
|
@ -61,9 +80,18 @@ function withTab(handler) {
|
||||||
}
|
}
|
||||||
function fromScript(code) {
|
function fromScript(code) {
|
||||||
return {
|
return {
|
||||||
|
async getattr(path) {
|
||||||
|
const tabId = parseInt(pathComponent(path, -2));
|
||||||
|
return {
|
||||||
|
st_mode: unix.S_IFREG | 0444,
|
||||||
|
st_nlink: 1,
|
||||||
|
st_size: stringSize((await browser.tabs.executeScript(tabId, {code}))[0])
|
||||||
|
};
|
||||||
|
},
|
||||||
async read(path, fh, size, offset) {
|
async read(path, fh, size, offset) {
|
||||||
const tabId = parseInt(pathComponent(path, -2));
|
const tabId = parseInt(pathComponent(path, -2));
|
||||||
return browser.tabs.executeScript(tabId, {code}).substr(offset, size);
|
return (await browser.tabs.executeScript(tabId, {code}))[0]
|
||||||
|
.substr(offset, size);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue