Support Binary field in CSV import/export

issue10350
review346101002
This commit is contained in:
Cédric Krier
2021-05-18 22:08:59 +02:00
parent dc5d6db505
commit e792cf10fa
4 changed files with 34 additions and 21 deletions
+2
View File
@@ -1,3 +1,5 @@
* Support Binary field in CSV import/export
Version 6.0.0 - 2021-05-03
* Bug fixes (see mercurial logs for details)
* Use appropriate types for email and url widgets
+27
View File
@@ -451,6 +451,33 @@
return Sao.TimeDelta(null, seconds);
};
Sao.common.btoa = function(value) {
var strings = [], chunksize = 0xffff;
// JavaScript Core has hard-coded argument limit of 65536
// String.fromCharCode can not be called with too many
// arguments
for (var j = 0; j * chunksize < value.length; j++) {
strings.push(String.fromCharCode.apply(
null, value.subarray(
j * chunksize, (j + 1) * chunksize)));
}
return btoa(strings.join(''));
};
Sao.common.atob = function(value) {
// javascript's atob does not understand linefeed
// characters
var byte_string = atob(value.base64.replace(/\s/g, ''));
// javascript decodes base64 string as a "DOMString", we
// need to convert it to an array of bytes
var array_buffer = new ArrayBuffer(byte_string.length);
var uint_array = new Uint8Array(array_buffer);
for (var j=0; j < byte_string.length; j++) {
uint_array[j] = byte_string.charCodeAt(j);
}
return uint_array;
};
Sao.common.ModelAccess = Sao.class_(Object, {
init: function() {
this.batchnum = 100;
+2 -21
View File
@@ -195,17 +195,7 @@
value = Sao.TimeDelta(null, value.seconds);
break;
case 'bytes':
// javascript's atob does not understand linefeed
// characters
var byte_string = atob(value.base64.replace(/\s/g, ''));
// javascript decodes base64 string as a "DOMString", we
// need to convert it to an array of bytes
var array_buffer = new ArrayBuffer(byte_string.length);
var uint_array = new Uint8Array(array_buffer);
for (var j=0; j < byte_string.length; j++) {
uint_array[j] = byte_string.charCodeAt(j);
}
value = uint_array;
value = Sao.common.atob(value);
break;
case 'Decimal':
value = new Sao.Decimal(value.decimal);
@@ -272,18 +262,9 @@
'decimal': value.toString()
};
} else if (value instanceof Uint8Array) {
var strings = [], chunksize = 0xffff;
// JavaScript Core has hard-coded argument limit of 65536
// String.fromCharCode can not be called with too many
// arguments
for (var j = 0; j * chunksize < value.length; j++) {
strings.push(String.fromCharCode.apply(
null, value.subarray(
j * chunksize, (j + 1) * chunksize)));
}
value = {
'__class__': 'bytes',
'base64': btoa(strings.join(''))
'base64': Sao.common.btoa(value),
};
} else {
value = jQuery.extend({}, value);
+3
View File
@@ -2063,6 +2063,9 @@
if ((i === 0) && indent && (typeof(val) == 'string')) {
val = ' '.repeat(indent) + val;
}
if (val instanceof Uint8Array) {
val = Sao.common.btoa(val);
}
row.push(val);
});
return row;