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

Fix issue 1365: support binary deserializers in CLI #1366

Merged
merged 3 commits into from
Nov 9, 2024

Conversation

eldanb
Copy link
Contributor

@eldanb eldanb commented Nov 2, 2024

All Submissions:

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?
  • Does your submission pass tests?

Note: please do NOT include build files (those generate by the build-xxx commands) with your PR,

Thank you for your help in advance, much appreciated !

CLI loads required files as binary (arraybuffer)
Tests
@z3dev
Copy link
Member

z3dev commented Nov 2, 2024

@eldanb Oh! You provided the changes. Nice!

The changes are fine except for one point. Each deserializer has a specific API, and changing those now in V2 is probably not a good idea. There are other applications using those deserializers. :(

I suggest doing something like the core library does, and choose the buffer contents based on file extension.

if (binaryMimetypes[ext]) {

Also, there are some new formats coming in V3, including 3MF. So, maybe the IO library needs another list, or extend the list of 'formats'. Then there's one place that keeps track of the required 'binary' versus 'string' contents.

@eldanb
Copy link
Contributor Author

eldanb commented Nov 2, 2024

But I didn't change the serializers' APIs.
Their API could always receive either an array buffer or a string (that's what happens in walkFiles). Some of them would fail when they get an array buffer. That's what I fixed.

To be clear -- anything that worked with the deserializers prior to my change would continue working with them.
Things that previously failed may now succeed (correctly)

@eldanb
Copy link
Contributor Author

eldanb commented Nov 2, 2024

Looking at binaryMimeTypes like this means that there are multiple places that encode the deserializer's expected API, which I recommend to avoid.

If you prefer we can decide that a deserializer function carries a "isBinary" property, and based on that we either load binary or text. But that too is more cumbersome, I believe, than simply declaring the deserializer's API (as it is now) as receiving "string or ArrayBuffer"

@z3dev

Copy link
Member

@z3dev z3dev left a comment

Choose a reason for hiding this comment

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

@eldanb a few questions and suggestions.

packages/core/src/io/registerExtensions.js Show resolved Hide resolved
packages/io/io-utils/ensureString.js Outdated Show resolved Hide resolved
packages/io/amf-deserializer/src/index.js Outdated Show resolved Hide resolved
@eldanb
Copy link
Contributor Author

eldanb commented Nov 5, 2024

@z3dev I've committed changes per your comments.
Note that I've not advanced any of the package's versions, I'm assuming this is something you do as part of your release/publish routine?

@z3dev
Copy link
Member

z3dev commented Nov 5, 2024

@z3dev I've committed changes per your comments.
Note that I've not advanced any of the package's versions, I'm assuming this is something you do as part of your release/publish routine?

Yeah. The version updates happen automatically via Lerna.

I'll double check.

@z3dev
Copy link
Member

z3dev commented Nov 5, 2024

@platypii please review

@z3dev z3dev requested a review from platypii November 5, 2024 11:01
Copy link
Contributor

@platypii platypii left a comment

Choose a reason for hiding this comment

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

The code looks fine, and I appreciate the tests.

However I have to admit I was unable to re-pro the issue? I downloaded example_project.zip from your issue #1365. But when I use the latest published cli, I don't get an error? Maybe I'm missing something?

(update: nevermind I see that I needed to run it on the whole folder to get the error)

@eldanb
Copy link
Contributor Author

eldanb commented Nov 5, 2024

To reproduce the issue you should require() the stl. There's a sample project there which I've added to the tests. Running the CLI on it fails. also the tests I added for back-loading projects fail without the fix.

@platypii
Copy link
Contributor

platypii commented Nov 5, 2024

Confirmed I was able to reproduce the failure on master, but success on this pr branch 👍

@z3dev
Copy link
Member

z3dev commented Nov 6, 2024

@eldanb these changes are all set to go.

fyi, there are coding style standards. But there are probably lots of exceptions in V2.

npm run lint

i will roll a release this weekend.

@z3dev z3dev merged commit 36b339f into jscad:master Nov 9, 2024
2 checks passed
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