changeset aea9ffab0b8b in sao:default
details: https://hg.tryton.org/sao?cmd=changeset&node=aea9ffab0b8b
description:
Support Binary field in CSV import/export
issue10350
review346101002
diffstat:
CHANGELOG | 2 ++
src/common.js | 27 +++++++++++++++++++++++++++
src/rpc.js | 23 ++---------------------
src/window.js | 3 +++
4 files changed, 34 insertions(+), 21 deletions(-)
diffs (101 lines):
diff -r 33d542c5df16 -r aea9ffab0b8b CHANGELOG
--- a/CHANGELOG Sun May 16 17:45:03 2021 +0200
+++ b/CHANGELOG Tue May 18 22:08:59 2021 +0200
@@ -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
diff -r 33d542c5df16 -r aea9ffab0b8b src/common.js
--- a/src/common.js Sun May 16 17:45:03 2021 +0200
+++ b/src/common.js Tue May 18 22:08:59 2021 +0200
@@ -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;
diff -r 33d542c5df16 -r aea9ffab0b8b src/rpc.js
--- a/src/rpc.js Sun May 16 17:45:03 2021 +0200
+++ b/src/rpc.js Tue May 18 22:08:59 2021 +0200
@@ -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);
diff -r 33d542c5df16 -r aea9ffab0b8b src/window.js
--- a/src/window.js Sun May 16 17:45:03 2021 +0200
+++ b/src/window.js Tue May 18 22:08:59 2021 +0200
@@ -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;