Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fix for iconv issue #549

Merged
merged 1 commit into from

2 participants

@idralyuk
Collaborator

See #548

@shimonchayim
Owner

Nice! Can you also port the change to 0.6 Branch?

@shimonchayim shimonchayim merged commit cb08775 into ql-io:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 6, 2012
  1. @idralyuk

    Fixed iconv issue: ql-io#548

    idralyuk authored
This page is out of date. Refresh to see the latest.
Showing with 18 additions and 7 deletions.
  1. +18 −7 modules/engine/lib/engine/source/verb.js
View
25 modules/engine/lib/engine/source/verb.js
@@ -70,21 +70,32 @@ var Verb = module.exports = function(table, statement, type, bag, path) {
return(key.join(':'));
}
};
- this['parse response'] = function(args) { // Just append bufs to a string
+ this['parse response'] = function(args) {
+ // figure out the encoding, default to utf8 if encoding is not provided
var encoding = 'UTF-8';
if(args.headers['content-type']) {
var contentType = headers.parse('content-type', args.headers['content-type'] || '');
encoding = contentType.params.charset ? contentType.params.charset :
contentType.subtype === 'csv' ? 'ASCII' : 'UTF-8';
}
- var str = '';
+
+ // calculate the length of the request
+ var length = 0, idx = 0;
+ _.each(args.body, function(b) {
+ length += b.length;
+ });
+
+ // create a buffer large enough to fit the entire request and copy the request into it
+ var buf = new Buffer(length);
+ _.each(args.body, function(b) {
+ idx = idx + b.copy(buf, idx);
+ });
+
var iconv = new Iconv(encoding, 'UTF-8');
- _.each(args.body, function(buf) {
- buf = (iconv.convert(buf));
- str += buf.toString('UTF-8');
- });
+ buf = (iconv.convert(buf)); // convert the buf to utf8
+
return {
- content: str
+ content: buf.toString('UTF-8')
};
};
this['patch response'] = function(args) {return args.body; };
Something went wrong with that request. Please try again.