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

Merge Format into MediaType #145

Merged
merged 2 commits into from
Dec 2, 2020
Merged

Merge Format into MediaType #145

merged 2 commits into from
Dec 2, 2020

Conversation

mickael-menu
Copy link
Member

  • Format got merged into MediaType, to simplify the media type APIs.
    • You can use MediaType.of() to sniff the type of a file or bytes.
    • MediaType has now optional name and fileExtension properties.
    • Some publication formats can be represented by several media type aliases. Using mediaType.canonicalized will give
      you the canonical media type to use, for example when persisting the file type in a database. All Readium APIs are
      already returning canonical media types, so it only matters if you create a MediaType yourself from its string
      representation.

Copy link
Contributor

@qnga qnga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, that's better this way.

Just one thing that was already here in the previous version: I'm not sure readFileSignature should decode bytes and return a String. Generally speaking, a magic number is a sequence of bytes, not necessarily a string. In the worst case, it might not make sense in any encoding. What do you think of it?

@mickael-menu
Copy link
Member Author

Just one thing that was already here in the previous version: I'm not sure readFileSignature should decode bytes and return a String. Generally speaking, a magic number is a sequence of bytes, not necessarily a string. In the worst case, it might not make sense in any encoding. What do you think of it?

You have a point, I'll update the proposal. I returned a string to make ASCII-based magic number (e.g. %PDF) more visible, but it can still be done on the client side of this API.

@mickael-menu
Copy link
Member Author

Although the API looks a bit contrived now: readFileSignature(length: Int) -> ByteArray?.

I think we might as well remove it and introduce read(range) -> ByteArray? instead.

@qnga
Copy link
Contributor

qnga commented Nov 12, 2020

Sounds good!

@mickael-menu mickael-menu merged commit 6704a4b into master Dec 2, 2020
@mickael-menu mickael-menu deleted the fix/format-api branch December 2, 2020 15:54
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

Successfully merging this pull request may close these issues.

3 participants