Skip to content

Flexability in temporary folder in StreamWriter files #2024

Closed
@eliyaoo32

Description

@eliyaoo32

The StreamWriter feature in Excelize is great for handling large XLSX file generation. Currently, temporary files are created using Golang's os.CreateTemp, as seen in stream.go#L740.

In some cases, relying on os.CreateTemp is not flexible enough. Specifically, there are scenarios where it's preferable to direct these temporary files to different or dynamically determined storage locations based on the request context. This restriction can limit the usage of StreamWriter in more complex environments.

I propose adding an option in StreamWriter to allow users to provide a custom temporary file creation method. This would follow the options pattern, maintaining the current behavior as the default. The user would be able to specify their own TempFileFactory, allowing for dynamic control over the temporary file path.

For example:

type TempFileFactory func() (*os.File, error)

var DefaultTempFileFactory TempFileFactory = func() {
    return os.CreateTemp(os.TempDir(), "excelize-")
}


// Line 740:
bw.tmp, err = newTempFile();

I have no problem to contribue this solution for the library if there is an agreement on a solution.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions