D
Deno

help

How to transform a Readable Stream to a file.

L.literfieber10/18/2022
I have a ReadableStream from a post request and i cant find a way to transform the body(ReadableStream) to a file. I tried to pipe the ReadableStream into a file like this const file = await Deno.open('./test.png', {create: true,write: true,}) myPostRequest.body.pipeTo(file.writable); file.close(); I always get: error: Uncaught (in promise) BadResource: Bad resource ID at async write (deno:ext/net/01_net.js:33:12) at async Object.write (deno:ext/net/01_net.js:82:25) what is the correct way to create a file from a readable stream ?
CcrowlKats10/18/2022
pipeTo is async, so you'd have to wait for it to complete before closing the file. also, you don't need to close the file manually, the pipeTo will do that automatically
L.literfieber10/18/2022
That worked but now it seems to have the wrong encoding I cant open it in a img viewer It seems like it is posted as multipart/form-data it might has some extra data in it that corrupts the output Ok i found the solution thanks for the help @crowlkats 😄 It seems like i had to parse it as multipart/form-data and then use the data content to create the file via Deno.writeFile()

Looking for more? Join the community!

Recommended Posts
Silence error logs on Oak serverI'm trying to silence specific errors on an Oak server on Deploy. A Github issue said to add an 'errAre pointers supported in Fast API return types?If no, how do I return pointers?Reddit fetch Vs. My noob brain part. IHello! So I want to fetch Reddit posts. I use this library. I have a few questions. https://github.cHow do I detect mouse clicks and key presses with Deno.stdin?I don't even really have any base code, so I was just wondering as to how do I do the problem specifML with FFISuppose you wish to do some machine learning stuff with Deno, would it be optimal to use FFI with C Is there a way to determine what modules have been dynamically imported at runtime?The builtin tools to compile/bundle/vendor don't account for dynamic imports (understandably), but iweird interfacehow can a class implement this interface ```ts interface I { (): void type: string }``` or a `cnpm specifier import typesso when I do something like ```ts import * as rx from 'npm:rxjs' console.log(rx) ``` I do have the error Unsupported scheme node for module `nodemodule`. Supported schemesI'm trying to import a module using: ```js import { example } from "npm:example"; ``` Inside `examplesbuild_deno_loader importing Deno modulesA dependancy I use imports modules like "fs" and I want esbuild_deno_loader to treat them as externaIs there a good dataframe library for deno?I use the nodejs bindings for pola.rs for now but I'd like to move from nodejs to deno. This is my ltype a whole directory to make sure each file in the directory exports a default module of a type.Can you type a whole directory to make sure that every file in the directory is exporting a default help mehow do i get the contents of the html, i tried this, but its not loggingextract generic type of generic classhow to get typeof generic type in generic class ```ts class GenericClass<T> {} ``` i want to extract