const delay = (ms) => new Promise(resolve => setTimeout(resolve, ms));
const chunksToSend = ['1', '2', '3'];
const stream = new ReadableStream({
async start(controller) {
for(const chunk of chunksToSend) {
await delay(1000);
controller.enqueue(chunk);
}
controller.close();
}
});
fetch('https://postman-echo.com/post', {
method: 'POST',
body: stream.pipeThrough(new TextEncoderStream()),
headers: {'Content-Type': 'text/plain'},
duplex: 'half',
})
.then(response => response.text())
.then(text => console.log('Response:', text));
Uint8Array
, потому тут используется .pipeThrough(new TextEncoderStream())
который собственно и делает этот массив из строки, но ты можешь в ручную чанки из Uint8Array
слать, если у тебя не строковые данные.Первый раз сталкиваюсь с такой проблемой.
const articleDB = new DB(json);
console.log(articleDB.get(1));
articleDB.delete(1);
for(const article of articleDB.byTagIterator('oracle')) {
console.log(article)
}
saveToFile(articleDB.toJSON());