Skip to content

Commit

Permalink
Explicitly write metadata values as integer type
Browse files Browse the repository at this point in the history
  • Loading branch information
georgestagg committed Sep 9, 2024
1 parent 00dfe4e commit 7bc5c52
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions R/tar.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ add_tar_index <- function(file, strip = 0) {
json <- charToRaw(jsonlite::toJSON(metadata, auto_unbox = TRUE))
magic <- charToRaw('webR')
reserved <- raw(4) # reserved for future use
block <- writeBin(as.integer(tar_end / 512), raw(), size = 4, endian = "big")
len <- writeBin(length(json), raw(), size = 4, endian = "big")
block <- writeBin(tar_end / 512, "integer", size = 4, endian = "big")
len <- writeBin(length(json), "integer", size = 4, endian = "big")
length(json) <- 4 * ceiling(length(json) / 4) # pad to 4 byte boundary
data <- c(data[1:tar_end], json, magic, reserved, block, len)

Expand Down
2 changes: 1 addition & 1 deletion inst/pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ articles:
mount-host-dir: mount-host-dir.html
rwasm: rwasm.html
tar-metadata: tar-metadata.html
last_built: 2024-09-04T08:58Z
last_built: 2024-09-09T10:04Z
urls:
reference: https://r-wasm.github.io/rwasm/reference
article: https://r-wasm.github.io/rwasm/articles
4 changes: 2 additions & 2 deletions vignettes/tar-metadata.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ A `.tar` archive that includes Emscripten filesystem metadata has the data layou
| 1 | Variable | JSON metadata, UTF8 encoded, padded with `0x00` to 4 byte boundary. |
| 2 | 4 bytes | Magic bytes: The string `"webR"`, UTF8 encoded (`0x77656252`). |
| 3 | 4 bytes | Reserved, currently `0x00000000`. |
| 4 | 4 bytes | Offset of JSON metadata (field 1), in units of 512-byte blocks. Signed integer, big endian. |
| 5 | 4 bytes | Length of JSON metadata, in bytes. Signed integer, big endian. |
| 4 | 4 bytes | Offset of JSON metadata, in units of 512-byte blocks. Signed integer, big endian. |
| 5 | 4 bytes | Length of JSON metadata, not including trailing null characters, in bytes. Signed integer, big endian. |
Table: Data layout for a `.tar` archive with filesystem metadata.

0 comments on commit 7bc5c52

Please sign in to comment.