Skip to content

Commit

Permalink
log for web
Browse files Browse the repository at this point in the history
  • Loading branch information
Trinidadec committed Nov 17, 2023
1 parent 0062e5a commit 62dcbac
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
1 change: 0 additions & 1 deletion index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ const getLocal = mem => io => async ([root, file]) => {

/** @type {(mem: Cache) => (host: string) => (io: IO) => (root: [string, string]) => Promise<number>} */
const getRemote = mem => host => io => async ([root, file]) => {
io.consoleLog(`getRemote ${root}`)
const tempFile = `_temp_${root}`
await io.write(tempFile, new Uint8Array())
/** @type {ForestGet} */
Expand Down
13 changes: 5 additions & 8 deletions web-test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,17 @@ d.getElementById('download').addEventListener('click', () => {
const fRead = fetchRead(host)(webIo)
/** @type {(forestNodeId: ForestNodeId) => Promise<Uint8Array>} */
const read = forestNodeId => {
// @ts-ignore
d.getElementById('log').innerText += `read from ${forestNodeId}\n`
webIo.consoleLog(`read from ${forestNodeId}\n`)
return fRead(forestNodeId)
}
/** @type {(b: Uint8Array) => Promise<void>} */
const write = async (b) => {
// @ts-ignore
d.getElementById('log').innerText += `write ${b.length}\n`
buffer = new Uint8Array([...buffer, ...b])
webIo.consoleLog(`write ${b.length}\n`)
buffer = new Uint8Array([...buffer, ...b])
}
get({ read, write })(hash).then(exitCode => {
if (exitCode !== null) {
// @ts-ignore
d.getElementById('log').innerText += `error exit code = ${exitCode}\n`
webIo.consoleLog(`error exit code = ${exitCode}\n`)
return
}

Expand All @@ -52,7 +49,7 @@ d.getElementById('download').addEventListener('click', () => {
// @ts-ignore
d.getElementById('output-text').style.display = 'block'
// @ts-ignore
d.getElementById('output-text').innerText = new TextDecoder().decode(buffer)
d.getElementById('output-text').innerText = new TextDecoder().decode(buffer)
})
});

Expand Down

0 comments on commit 62dcbac

Please sign in to comment.