Skip to content
New issue

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

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

Already on GitHub? # to your account

Improve convert interface #47

Merged
merged 1 commit into from
Nov 25, 2024
Merged

Conversation

nirs
Copy link
Member

@nirs nirs commented Nov 21, 2024

Creating a converter and calling converter.Convert() feels too complicated for no reason. We need to keep state during the conversion, but the user does not need to care about the internals.

Since we already made incompatible changes and clients like lima need to change, this is an opportunity to get the interface right so future changes can be backward compatible.

Changes:

  • Convert() is now a function accepting Options, saving one step for the caller.
  • The progress argument is now a Progress option, so users do not need to pass nil to disable progress.
  • The size argument was removed since we can use the size of the image. If we want to support a byte range we can add start and length options without changing the function signature.
  • Converter renamed to conversion, created inside Convert()
  • Since we create a new conversion for each call, we don't need reset()
  • Adding future options will not change the function signature

Example usage using defaults:

convert.Convert(target, img, convert.Options{})

Example usage with progress bar:

convert.Convert(target, img, convert.Options{Progress: bar})

Lima pr: lima-vm/lima#2933

Creating a converter and calling converter.Convert() feels too
complicated for no reason. We need to keep state during the conversion,
but the user does not need to care about the internals.

Since we already made incompatible changes and clients like lima need to
change, this is an opportunity to get the interface right so future
changes can be backward compatible.

Changes:

- `Convert()` is now a function accepting `Options`, saving one step for
  the caller.
- The progress argument is now a `Progress` option, so users do not need
  to pass nil to disable progress.
- The size argument was removed since we can use the size of the image.
  If we want to support a byte range we can add start and length
  options without changing the function signature.
- `Converter` renamed to `conversion`, created inside `Convert()`
- Since we create a new `conversion` for each call, we don't need
  `reset()`
- Adding future options will not change the function signature

Example usage using defaults:

    convert.Convert(target, img, convert.Options{})

Example usage with progress bar:

    convert.Convert(target, img, convert.Options{Progress: bar})

Signed-off-by: Nir Soffer <nirsof@gmail.com>
@nirs nirs requested review from a team and removed request for a team November 21, 2024 18:56
nirs added a commit to nirs/lima that referenced this pull request Nov 21, 2024
For testing:
lima-vm/go-qcow2reader#47

Signed-off-by: Nir Soffer <nirsof@gmail.com>
nirs added a commit to nirs/lima that referenced this pull request Nov 21, 2024
We cannot track conversion progress using the image, since convert reads
only the allocated extents of the image. We need to pass the progress
bar using convert.Options.

pb.ProgressBar need to be adapted to convert.Updater interface, so
progressbar returns now our own type. This can be used later for other
improvement like hiding the progress bar.

Testing lima-vm/go-qcow2reader#47

Signed-off-by: Nir Soffer <nirsof@gmail.com>
@AkihiroSuda AkihiroSuda added this to the v0.5.1 (tentative) milestone Nov 25, 2024
Copy link
Member

@AkihiroSuda AkihiroSuda left a comment

Choose a reason for hiding this comment

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

Thanks

@AkihiroSuda AkihiroSuda merged commit fb7b18e into lima-vm:master Nov 25, 2024
2 checks passed
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants