From 5577c3ab5a21a90f2d3e6c6debf7ed25efb347d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20Szab=C3=B3?= Date: Sun, 4 Sep 2016 00:07:53 +0200 Subject: [PATCH] Fix GalleryStorageService GalleryStorageService is sending JSON so it couldn't serialize the ArrayBuffer which came from serializing the Piskel. In this commit it sends the ArrayBuffer as an Array to the server so it can store it easily. --- src/js/service/storage/GalleryStorageService.js | 2 +- src/js/utils/serialization/Deserializer.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/js/service/storage/GalleryStorageService.js b/src/js/service/storage/GalleryStorageService.js index 3169d831..7d0f8a90 100644 --- a/src/js/service/storage/GalleryStorageService.js +++ b/src/js/service/storage/GalleryStorageService.js @@ -12,7 +12,7 @@ var deferred = Q.defer(); var data = { - framesheet : this.piskelController.serialize(), + framesheet : '[' + new Uint8Array(this.piskelController.serialize()) + ']', fps : this.piskelController.getFPS(), name : descriptor.name, description : descriptor.description, diff --git a/src/js/utils/serialization/Deserializer.js b/src/js/utils/serialization/Deserializer.js index e80773f4..35d630bb 100644 --- a/src/js/utils/serialization/Deserializer.js +++ b/src/js/utils/serialization/Deserializer.js @@ -10,7 +10,7 @@ var modelVersion; var isJSON = false; - if (data instanceof ArrayBuffer) { + if (data instanceof ArrayBuffer || data instanceof Array) { var uint8 = new Uint8Array(data); // Backward compatibility for JSON (modelVersion < 3) @@ -22,7 +22,7 @@ data = JSON.parse(data); modelVersion = data.modelVersion; } else { - var arr16 = new Uint16Array(data); + var arr16 = new Uint16Array(uint8.buffer); modelVersion = arr16[0]; } } else { @@ -47,7 +47,7 @@ var j; var buffer = this.data_; var arr8 = new Uint8Array(buffer); - var arr16 = new Uint16Array(buffer); + var arr16 = new Uint16Array(arr8.buffer); var sub; /********/