Skip to content
This repository has been archived by the owner on Mar 9, 2019. It is now read-only.

Implement io.WriterTo interface on Tx. #330

Merged
merged 1 commit into from
Mar 22, 2015

Conversation

benbjohnson
Copy link
Member

Overview

This pull request moves the functionality in Tx.Copy() to Tx.WriteTo(). This allows Tx to be used as an io.WriterTo which makes it easier to mock.

The Tx.Copy() function still exists but it's simply a wrapper around Tx.WriteTo().

@baijum
Copy link
Contributor

baijum commented Mar 18, 2015

👍

How about updating Database backups section in the README.md to use this new API?

This commit moves the functionality in Tx.Copy() to Tx.WriteTo(). This
allows Tx to be used as an io.WriterTo which makes it easier to mock.

The Tx.Copy() function still exists but it's simply a wrapper around
Tx.WriteTo().
@benbjohnson
Copy link
Member Author

Good catch! I updated the docs in 8c6af54.

benbjohnson added a commit that referenced this pull request Mar 22, 2015
Implement io.WriterTo interface on Tx.
@benbjohnson benbjohnson merged commit a965199 into boltdb:master Mar 22, 2015
@benbjohnson benbjohnson deleted the tx-writer-to branch March 22, 2015 21:26
@@ -343,7 +343,8 @@ func BackupHandleFunc(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Content-Type", "application/octet-stream")
w.Header().Set("Content-Disposition", `attachment; filename="my.db"`)
w.Header().Set("Content-Length", strconv.Itoa(int(tx.Size())))
return tx.Copy(w)
_, err := tx.WriteTo(w)
return err
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the benefit of writing 2 lines to use tx.WriteTo instead of the original 1 line with tx.Copy?

Copy link
Member Author

Choose a reason for hiding this comment

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

There's no benefit, necessarily. I mainly like to stick with the stdlib interfaces where possible.

Copy link
Contributor

Choose a reason for hiding this comment

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

👍 thanks for answering.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants