zamfofex
zamfofex
DDeno
Created by Kay on 3/1/2024 in #help
Get image from automated download
See if this is satisfying enough! deno run -A cube.js
32 replies
DDeno
Created by Kay on 3/1/2024 in #help
Get image from automated download
If you just want an isometric image, you could create it without Three.js.
32 replies
DDeno
Created by Kay on 3/1/2024 in #help
Get image from automated download
I guess Three.js might not be possible, actually. 🤔
32 replies
DDeno
Created by Kay on 3/1/2024 in #help
Get image from automated download
But note that you can just run that code on Deno itself if you use the right tools, instead of having it run on a browser.
32 replies
DDeno
Created by Kay on 3/1/2024 in #help
Get image from automated download
I’m not sure you can easily/seamlessly just have Deno save the file from the browser JavaScript code.
32 replies
DDeno
Created by Kay on 3/1/2024 in #help
Get image from automated download
It seems like you’re actually downloading the page’s source instead of the image you want.
32 replies
DDeno
Created by Kay on 3/1/2024 in #help
Get image from automated download
marvinh’s code works for me. Are you sure the file being served is the same?
32 replies
DDeno
Created by spirobel on 2/25/2024 in #help
How to feed a ReadableStream / async Generator into a Response object?
If you want to be able to mix and match strings and buffers, you need a preprocessor function like this:
// mix strings and buffers

Deno.serve(request => new Response(ReadableStream.from(preprocess(request))))

let encoder = new TextEncoder()

async function * preprocess(request)
{
for await (let chunk of makeStream(request))
{
if (typeof chunk === "string") chunk = encoder.encode(chunk)
yield chunk
}
}

async function * makeStream(request)
{
yield "Hello, "
yield encoder.encode("world!")
}
// mix strings and buffers

Deno.serve(request => new Response(ReadableStream.from(preprocess(request))))

let encoder = new TextEncoder()

async function * preprocess(request)
{
for await (let chunk of makeStream(request))
{
if (typeof chunk === "string") chunk = encoder.encode(chunk)
yield chunk
}
}

async function * makeStream(request)
{
yield "Hello, "
yield encoder.encode("world!")
}
Otherwise, you can get away with only buffers or only strings more easily:
// only buffers
Deno.serve(request => new Response(ReadableStream.from(makeStream(request))))

let encoder = new TextEncoder()

async function * makeStream(request)
{
yield encoder.encode("Hello, ")
yield encoder.encode("world!")
}
// only buffers
Deno.serve(request => new Response(ReadableStream.from(makeStream(request))))

let encoder = new TextEncoder()

async function * makeStream(request)
{
yield encoder.encode("Hello, ")
yield encoder.encode("world!")
}
// only strings
Deno.serve(request => new Response(ReadableStream.from(makeStream(request)).pipeThrough(new TextEncoderStream())))

async function * makeStream(request)
{
yield "Hello, "
yield "world!"
}
// only strings
Deno.serve(request => new Response(ReadableStream.from(makeStream(request)).pipeThrough(new TextEncoderStream())))

async function * makeStream(request)
{
yield "Hello, "
yield "world!"
}
9 replies