Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Unknown encoding: buffer" error when using Safari #42

Open
daniel7912 opened this issue Apr 2, 2015 · 4 comments
Open

"Unknown encoding: buffer" error when using Safari #42

daniel7912 opened this issue Apr 2, 2015 · 4 comments

Comments

@daniel7912
Copy link

Hi,

I have set up an upload system which reports progress etc, all taken from the main github page. Code:

Client

var stream = ss.createStream();
ss(Socket).emit('beginUpload', stream, $scope.video);

var blobStream = ss.createBlobReadStream($scope.videoFile);
var size = 0;

$scope.uploading = true;

blobStream.on('data', function(chunk) {
    size += chunk.length;
    var progress = (size / $scope.videoFile.size * 100).toFixed(2);
    //console.log('progress', progress);
    if (progress != 100) {
        updateProgress(progress);
    }
});

blobStream.on('error', function(err) {
    console.log('ERROR', err);
});

blobStream.on('end', function() {
    Socket.emit('uploadComplete', $scope.video);
});

blobStream.pipe(stream);

Server

ss(socket).on('beginUpload', function(stream, data) {

    // Save stream to file
    var filename = config.upload.tmpFolder+'/'+data.filename;

    stream.pipe(fs.createWriteStream(filename)).on('error', function(err) {
        console.log('crashed at begin upload', err);
    });
});

This works perfectly on Chrome/Firefox & Internet Explorer from my tests, but for reason using Safari causes the following error on the server:

buffer.js:377
      throw new TypeError('Unknown encoding: ' + encoding);
            ^
TypeError: Unknown encoding: buffer
    at Buffer.write (buffer.js:377:13)
    at new Buffer (buffer.js:215:28)
    at IOStream.Readable.push (_stream_readable.js:122:15)
    at push (/home/user/www/node_modules/socket.io-stream/lib/iostream.js:147:20)
    at IOStream._onwrite (/home/user/www/node_modules/socket.io-stream/lib/iostream.js:153:5)
    at Socket._onwrite (/home/user/www/node_modules/socket.io-stream/lib/socket.js:231:10)
    at Socket.<anonymous> (/home/user/www/node_modules/socket.io-stream/node_modules/component-bind/index.js:21:15)
    at Socket.EventEmitter.emit (events.js:106:17)
    at Socket.onevent (/home/user/www/node_modules/socket.io/lib/socket.js:327:8)
    at Socket.onpacket (/home/user/www/node_modules/socket.io/lib/socket.js:287:12)

Am I doing something wrong or is this a problem?

@nkzawa
Copy link
Owner

nkzawa commented Apr 5, 2015

Umm, your code looks nothing wrong for me, and tests was passed on safari last time.
How did you use the library on client side? I suspect browserify used to build the library might too old now.

@daniel7912
Copy link
Author

I downloaded the zip from the github page and added socket.io-stream.js to my code manually, then used the javascript from my previous post to use it.

Looks like I downloaded it on 2nd March 2015.

@daniel7912
Copy link
Author

I updated both socket.io (I found I was using version 1.1.0) and socket.io-stream to the latest versions and now the error looks like this:

events.js:72
        throw er; // Unhandled 'error' event
              ^
TypeError: Unknown encoding: buffer
    at Buffer.write (buffer.js:377:13)
    at new Buffer (buffer.js:215:28)
    at IOStream.Readable.push (_stream_readable.js:122:15)
    at push (/home/user/www/node_modules/socket.io-stream/lib/iostream.js:147:20)
    at IOStream._onwrite (/home/user/www/node_modules/socket.io-stream/lib/iostream.js:153:5)
    at Socket._onwrite (/home/user/www/node_modules/socket.io-stream/lib/socket.js:231:10)
    at Socket.<anonymous> (/home/user/www/node_modules/socket.io-stream/node_modules/component-bind/index.js:21:15)
    at Socket.EventEmitter.emit (events.js:106:17)
    at Socket.onevent (/home/user/www/node_modules/socket.io/lib/socket.js:330:8)
    at Socket.onpacket (/home/user/www/node_modules/socket.io/lib/socket.js:290:12)

@nkzawa
Copy link
Owner

nkzawa commented Apr 19, 2015

Can you post your code which I can reproduce the issue if possible?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants