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

Improve convert interface #47

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

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 <[email protected]>
@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
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 <[email protected]>
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.

1 participant