Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions extensions/weavedrive/client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ function drive.getBlock(height)
if not block then
return nil, "Block Header not found!"
end
local headers = require("json").decode(block:read(block:seek("end")))
local size = block:seek("end")
block:seek("set")
local headers = require("json").decode(block:read(size))
block:close()
return headers
end
Expand All @@ -20,7 +22,9 @@ function drive.getTx(txId)
if not file then
return nil, "File not found!"
end
local contents = require("json").decode(file:read(file:seek("end")))
local size = file:seek("end")
file:seek("set")
local contents = require("json").decode(file:read(size))
file:close()
return contents
end
Expand All @@ -30,7 +34,9 @@ function drive.getData(txId)
if not file then
return nil, "File not found!"
end
local contents = file:read(file:seek("end"))
local size = file:seek("end")
file:seek("set")
local contents = file:read(size)
file:close()
return contents
end
Expand Down
7 changes: 7 additions & 0 deletions extensions/weavedrive/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,13 @@ module.exports = function weaveDrive (mod, FS) {
mod.HEAP8.set(stream.node.contents.subarray(0, toRead), dstPtr)
return toRead
}

// console.log(`stream.node.total_size: ${stream.node.total_size}, stream.position: ${stream.position}, to_read: ${to_read}`)
if (stream.position >= stream.node.total_size) {
// console.log("WeaveDrive: EOF reached.")
return 0;
}

// Satisfy what we can with the cache first
let bytesRead = this.readFromCache(stream, dstPtr, toRead)
stream.position += bytesRead
Expand Down