1

I using StreamSaver and NodeJS together for save 10,000,000 Records into a file with .Json format. After run app and downloaded about many records(200,000 or 300,000 or ....), downloading canceled and abort file.json and show error "Network failed" on downloader in browser.
Why show this error and canceled downloading?
Notice: I haven't any error in console and I downloaded about 500MB or more...So no problem in range/memory.

Server.js

var http = require('http');
var express = require('express');
var app = express();
var server = http.Server(app);
var io = require('socket.io')(server);

io.on('connection', function (socket) {
    console.log('Connection is ready!')
    socket.on('get_records', function (data) {
    var connection = new sql.Connection(config, function (err) {
        if (err) {
            console.log(err.message);
        }

        var request = new sql.Request(connection);
        request.stream = true;

        request.query("Select * from my_table");
        // ... error checks
        request.on('recordset', function (recordset) {
            // Emitted once for each recordset in a query
        });

        request.on('row', function (record) {
            // Emitted for each row in a recordset
            socket.emit('recieve_records', record); //send record by record to client
        });

        request.on('error', function (err) {
            console.log(err.message);
        });

        request.on('done', function (returnValue) {
            // Always emitted as the last one
        });
    });
});

client.js

var fileStream = streamSaver.createWriteStream('filename.json');
writer = fileStream.getWriter();
encoder = new TextEncoder();
var counter = 0;

socket.on('recieve_records', function (data) {
    var uint8array = encoder.encode(data + "\n"); // data='every things'
    writer.write(uint8array);
    counter++;
    if (counter > 100000) {
       console.log('100.000 messages downloaded');
       counter = 0;
    }
});

enter image description here

  • What is exact error message? Why do you set file extension to `.json` at `.createWriteStream()` if data is `.csv`? Does `.write()` expect a `TypedArray` or string? Have you tried sending data in two responses at 500,000 records each? – guest271314 Feb 15 '17 at 23:48
  • What is exact error message? – guest271314 Feb 16 '17 at 00:05
  • Is error a `RangeError`? – guest271314 Feb 16 '17 at 00:19
  • 1
    @guest271314 no....that occured in different time...edited question. –  Feb 16 '17 at 00:21
  • Greater detail as to what exact error is should be available. You can alternatively use `fetch()`, `ReadableStream`, `Response.body.getReader()`, see [How to solve Uncaught RangeError when download large size json](http://stackoverflow.com/questions/39959467/how-to-solve-uncaught-rangeerror-when-download-large-size-json), where was able to download an 189 MB file. – guest271314 Feb 16 '17 at 00:25
  • 1
    @guest271314 I downloaded about **~500MB**. 189MB is not problem. –  Feb 16 '17 at 00:29
  • 1
    @guest271314 I haven't any error in console. –  Feb 16 '17 at 00:31
  • Where is error occurring? Is full message of error _"Network failed"_? If 189 MB is not an issue, download 189 MB at a time using pattern where no issue occurred. – guest271314 Feb 16 '17 at 00:34
  • 1
    @guest271314 added pic into my question. please see again –  Feb 16 '17 at 00:44
  • The image does not provide additional description of source of error. – guest271314 Feb 16 '17 at 00:53
  • 1
    This is sample... –  Feb 16 '17 at 00:56
  • 1
    I will add a address tomorrow for check this item for u.... –  Feb 16 '17 at 00:58

0 Answers0