-
Notifications
You must be signed in to change notification settings - Fork 147
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
storage.get(key, { type })
#528
Comments
This looks like a nice improvement to me. I suppose the typing would also be improved by looking at the |
Instead of using |
Validation is another topic (for object/json), these are data types. |
Oh, I didn't notice this! What is the current plan for the actual data type within the storage itself? Personally I think this should be customizable depending on the actual project's requirement. But what default? |
Also, could this be the correct time to add optional compression? Recently, as I was experimenting with custom drivers with built-in compression, I've noticed that I could directly return the compressed data (1:1 from the storage) as the response from Nitro event handlers (while also adding correct headers). This became particularly useful for me because I could cache event handlers and Nuxt pages more efficiently (about 2/3 of server memory saved. No benchmark yet, just watching the resource monitor every few hours) |
I don't know if you've already seen it, but there is an open issue for compression: #94 I've also been using a custom driver to implement compression for unstorage and using it as the backing store for Nitro's page cache. But I think in this case it's not the best approach. Compressing the response in Nitro and storing it as-is in the cache storage makes it straightforward to directly send the compressed response without decompressing. To do this with an unstorage driver would require an asymmetric behavior where you compress on |
indeed I don't use |
Describe the feature
Currently, unstorage has two ways to access items:
getItem(key)
: Returns a json parsed value if parsable or fallback to textThis is an unpredictable behavior and also introduced two sets of methods.
We could support
storage.get(key, { type: "text" | "json" | "bytes" | "stream" | "blob" })
API to unify this and also make behavior more predictable.undio can potentially be integrated or we might end-up directly adding small utils in unstorage core to convert
Additional information
The text was updated successfully, but these errors were encountered: