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

Add a WriteTo method that implements the io.WriterTo interface #260

Merged

Conversation

VinGarcia
Copy link
Contributor

When reading the docs looking for a way of streaming the PDF as an HTTP response I actually skipped over the Write(io.Reader) error function because the name made me think it was an implementation of the io.Writer interface.

But it is not and its behavior actually is the behavior described by the io.WriterTo interface.

So I thought it was worth submitting this PR that basically renames the Write function to WriteTo changing its signature slightly to match the io.WriterTo interface.

The main goal here is to make the code easier to use for new comers by using a more canonical name for this function.

In order to keep retro-compatibility the old Writer method was not deleted but I've added a deprecation note.

It was also necessary to change the countingWriter.offset variable from int to int64 to comply with the io.WriterTo interface. A less intrusive implementation could be written where we could just convert from int to int64 when returning on the WriteTo method, but this could potentially cause an overflow of that integer eventually.

Feel free to ask me for any changes or even to change it yourself. I am all in favor of productivity and I know how little time we have to maintain these open-source projects.

This commit also adds a few comments and a deprecation note to the
existing `Write(io.Writer) error` method which can now be replaced with
the `WriteTo(io.Writer) (n int64, err error)` method.
func (gp *GoPdf) formatXrefline(n int) string {
str := strconv.Itoa(n)
func (gp *GoPdf) formatXrefline(n int64) string {
str := strconv.FormatInt(n, 10)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The strconv.Itoa function accepts an int as argument, so it was necessary to use FormatInt instead since n is now an int64.

@oneplus1000 oneplus1000 merged commit c7fca9c into signintech:master Jun 22, 2023
2 checks passed
@oneplus1000
Copy link
Collaborator

I don't have any questions. You explain everything very clear, even someone who is not strong English like me can understand easily and I have done merged pull request, thank you very much.

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.

None yet

2 participants