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 TempFileStorage #19

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

skycoop
Copy link

@skycoop skycoop commented Sep 20, 2024

I realized while implementing form-data-parser in a project that LocalFileStorage is a bad fit for apps that process uploads before persisting them elsewhere. I wanted something that wrote to a temporary directory that was removed at the end of the request handler and was only initialized if the form data contained a file. So I wrote TempFileStorage and wanted to contribute it back for others to use 😄

The biggest uncertainty I have about this change is the support for AsyncDisposable in the general node ecosystem.

@skycoop skycoop force-pushed the skycoop/temp-file-storage branch from 23d8762 to 745b2cd Compare September 20, 2024 18:45
@skycoop skycoop force-pushed the skycoop/temp-file-storage branch from 745b2cd to 3071b89 Compare September 20, 2024 18:48

describe('TempFileStorage', () => {
it('stores and retrieves files', async () => {
await using storage = new TempFileStorage('test-');
Copy link
Owner

Choose a reason for hiding this comment

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

Whoa, this is new to me! I've never seen using before. Very cool.

Copy link
Owner

@mjackson mjackson left a comment

Choose a reason for hiding this comment

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

Thank you for the PR! This is very cool.

Since AsyncDisposable is so new, would you be open to publishing this package yourself? At least until we can determine if it's going to be generally useful for many people?

The whole idea with the FileStorage interface is that hopefully there will be many implementations for different storage backends, and people can just plug in whichever one they need for a given use case. I'd be happy to link to your package in the README to help others find it more easily.

@skycoop
Copy link
Author

skycoop commented Sep 26, 2024

I have added use as a method to get automatic cleanup without await using and improved the documentation and tests on the class in the hopes it makes the class more generally useful. I can definitely publish this on my own if you prefer, but I believe that it's generic and useful enough to belong in the base package.

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.

2 participants