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

Change handler interface for lazy loading of unknown-sized elements #6

Open
remko opened this issue Jun 14, 2020 · 0 comments
Open
Labels

Comments

@remko
Copy link
Owner

remko commented Jun 14, 2020

Change the following methods on the Handler interface:

HandleBinary(ElementID, []byte, ElementInfo) error
HandleString(ElementID, string, ElementInfo) error

to

HandleBinary(ElementID, io.Reader, ElementInfo) error
HandleString(ElementID, io.Reader, ElementInfo) error

This allows handlers to only read part of the data (in case it is too much for them to process).
Alternatively, change the signature to

HandleBytes(ElementID, BytesType, io.Reader, ElementInfo)

where BytesType is String or Binary.

The following line needs to be added to all existing handlers to fix compilation for binary cases.

HandleBinary(id ElementID, r io.Reader, info ElementInfo) error {
  data, _ := ioutil.ReadAll(r)
  // use data as before. should be safe to ignore errors (the parser will handle these)
}

To make it more convenient, consider adding a convenience function:

HandleBinary(id ElementID, r io.Reader, info ElementInfo) error {
  data := mkvparse.ReadBytes(r)
  // use data as before
}

Because reading strings require more code, a convenience function for strings is useful:

HandleString(id ElementID, r io.Reader, info ElementInfo) error {
  str := mkvparse.ReadString(r)
  // use str as before
}

The Read* functions probably need a parameter to limit the size of the read (with -1 to mean 'Unlimited')

Another alternative is to add an UnsafeHandler interface, and adapt it to the new handler interface:

ParsePath("example.mkv", NewUnsafeHandler(unsafeHandler))
@remko remko added the proposal label Jan 24, 2022
@remko remko changed the title Proposal: Change handler interface for lazy loading of unknown-sized elements Change handler interface for lazy loading of unknown-sized elements Jan 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant