Skip to content

Allow user to wrap an existing write function #21

@adowair

Description

@adowair

First off, thank you @natefinch and all for putting this tool together!

I have the following usecase and wonder if this project can be extended to support it: today, atomic.WriteFile() uses io.Copy() to do the actual I/O to the temporary file. io.Copy is called with os.File and io.Reader, which makes a lot of sense for most cases. I have a particular case where I would like to override the I/O behavior, but still have the file write be atomic.

Can we consider introducing a new function NewWriter() (or WrapWriter()), like so:

func NewWriter(w func(filename string, r io.Reader) error) func(string, io.Reader) error {
  return func(...) error {
    // Create temp file
    // Call w
    // Sync and rename resultant file
}

Is this within the purview of the project? If so and if people are happy with this proposal, I am happy to submit a PR for this. Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions