Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

file format detection #528

Open
Jxck opened this issue Nov 11, 2019 · 0 comments
Open

file format detection #528

Jxck opened this issue Nov 11, 2019 · 0 comments

Comments

@Jxck
Copy link

Jxck commented Nov 11, 2019

in https://wicg.github.io/webpackage/draft-yasskin-wpack-bundled-exchanges.html#rfc.section.3.3

  1. If reading 10 bytes from stream returns an error or doesn’t return the bytes with hex encoding “86 48 F0 9F 8C 90 F0 9F 93 A6” (the CBOR encoding of the 6-item array initial byte and 8-byte bytestring initial byte, followed by 🌐📦 in UTF-8), return a “format error”.

I think this will cause implements like below

head = read_first_10_byte(path)

if (head == [86 48 F0 9F 8C 90 F0 9F 93 A6]) {
  // this is web bundle
  switch (parse_cbor(path)['version']) {
    // version switch
  }
} else {
  // this is not web bundle
}

but if webbundle format will change like below in the future. and also version ++.

webbundle = [
  magic
  version // *2*
  primary-url
  section-lengths
  sections
  extension // *new*
  length
]

the length of array will increase and first 10 byte will change.

this cause previous code not working, should be like this

head = read_first_10_byte(path)

if (head == [86 48 F0 9F 8C 90 F0 9F 93 A6]) {
  // this is web bundle
  switch (parse_cbor(path)['version']) {
    // version switch
  }
} else if (head == [*87* 48 F0 9F 8C 90 F0 9F 93 A6]
  // this is also new web bundle
  switch (parse_cbor(path)['version']) {
    // version switch
  }
} else {
  // this is not web bundle
}

so, this version model is not allow adding meta-section to webbundle cbor array.
if you think cbor array should not change from 6 forever, it works.
but I think it seems better to find other way to

  1. magic number should usable for file detection
  2. cbor structure update could detect by version, and not affect to 1

for example

webbundle = [
  magic
  body
  length
]

body = [
  version
  primary-url
  section-lengths
  sections
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant