FjordWarden
FjordWarden
Explore posts from servers
DDeno
Created by FjordWarden on 10/25/2023 in #help
Can't upgrade request to websocket
Oh, ok sorry I get it know, that error is normal if you don't connect with a websocket...
11 replies
DDeno
Created by FjordWarden on 10/25/2023 in #help
Can't upgrade request to websocket
Look, for some reason I keep having issues just running the example code. if I run the example from the blog, I just added an explicit version number, it still doesn't work:
import { Application, Router } from "https://deno.land/x/[email protected]/mod.ts";
const app = new Application({ logErrors: false });
const router = new Router();
router.get("/wss", (ctx) => {
if (!ctx.isUpgradable) {
ctx.throw(501);
}
const ws = ctx.upgrade();
ws.onopen = () => {
console.log("Connected to client");
ws.send("Hello from server!");
};
ws.onmessage = (m) => {
console.log("Got message from client: ", m.data);
ws.send(m.data);
ws.close();
};
ws.onclose = () => console.log("Disconncted from client");
});
app.use(router.routes());
app.use(router.allowedMethods());
app.listen({ port: 8000 });
import { Application, Router } from "https://deno.land/x/[email protected]/mod.ts";
const app = new Application({ logErrors: false });
const router = new Router();
router.get("/wss", (ctx) => {
if (!ctx.isUpgradable) {
ctx.throw(501);
}
const ws = ctx.upgrade();
ws.onopen = () => {
console.log("Connected to client");
ws.send("Hello from server!");
};
ws.onmessage = (m) => {
console.log("Got message from client: ", m.data);
ws.send(m.data);
ws.close();
};
ws.onclose = () => console.log("Disconncted from client");
});
app.use(router.routes());
app.use(router.allowedMethods());
app.listen({ port: 8000 });
The code does not run past if (!ctx.isUpgradable) ...
11 replies
DDeno
Created by FjordWarden on 10/25/2023 in #help
Can't upgrade request to websocket
I want to use oak
11 replies
DDeno
Created by FjordWarden on 10/25/2023 in #help
Can't upgrade request to websocket
Yes, that works but I'm trying to migrate to oak . I can't imagine what I am doing wrong as I am just following the documentation.
11 replies
DDeno
Created by FjordWarden on 9/29/2023 in #help
BDD with async tests
Sorry but this AI is stupid, I am asking about the funciton in the deno std
3 replies
DDeno
Created by FjordWarden on 9/6/2023 in #help
Read CSV files inside zip file using the web streams API
I've managed to make the example self containing and can run without a zip file. But I still haven't found a way I can read the unzipped file as a csv. Somehow I should be able to wrap it in some way, but the streaming api is very confusing.
import {Uint8ArrayWriter,Uint8ArrayReader,TextReader,ZipReader,ZipWriter} from 'https://deno.land/x/zipjs/index.js'
import {readCSV,CSVReader} from 'https://deno.land/x/csv/mod.ts'
import {CsvParseStream} from 'https://deno.land/[email protected]/csv/mod.ts'


async function streamToString(stream) {
const {done,value} = await stream.getReader().read()
return done ? '' : new TextDecoder().decode(value,{stream:true})
}

const zipWriter = new ZipWriter(new Uint8ArrayWriter());
await Promise.all([
zipWriter.add("a.csv", new TextReader("a,b,c\nd,e,f")),
zipWriter.add("b.csv", new TextReader("g,h,i\nj,k,l"))])
const zipFile = await zipWriter.close()
const zipReader = new ZipReader(new Uint8ArrayReader(zipFile))
for (const entry of await zipReader.getEntries()) {
console.log('file ', entry.filename)
const transformStream = new TransformStream()
const promiseText = streamToString(transformStream.readable)
await entry.getData(transformStream.writable)
const text = await promiseText
console.log(text)
}
await zipReader.close()
import {Uint8ArrayWriter,Uint8ArrayReader,TextReader,ZipReader,ZipWriter} from 'https://deno.land/x/zipjs/index.js'
import {readCSV,CSVReader} from 'https://deno.land/x/csv/mod.ts'
import {CsvParseStream} from 'https://deno.land/[email protected]/csv/mod.ts'


async function streamToString(stream) {
const {done,value} = await stream.getReader().read()
return done ? '' : new TextDecoder().decode(value,{stream:true})
}

const zipWriter = new ZipWriter(new Uint8ArrayWriter());
await Promise.all([
zipWriter.add("a.csv", new TextReader("a,b,c\nd,e,f")),
zipWriter.add("b.csv", new TextReader("g,h,i\nj,k,l"))])
const zipFile = await zipWriter.close()
const zipReader = new ZipReader(new Uint8ArrayReader(zipFile))
for (const entry of await zipReader.getEntries()) {
console.log('file ', entry.filename)
const transformStream = new TransformStream()
const promiseText = streamToString(transformStream.readable)
await entry.getData(transformStream.writable)
const text = await promiseText
console.log(text)
}
await zipReader.close()
Also this example hangs after executing.
2 replies
DDeno
Created by FjordWarden on 7/9/2023 in #help
Sanitize multiple test steps
No you are actually right I think, I've added the awaits and now ny sample is working
5 replies
DDeno
Created by FjordWarden on 7/9/2023 in #help
Sanitize multiple test steps
5 replies