mirror of
https://github.com/piskelapp/piskel.git
synced 2023-08-10 21:12:52 +03:00
Move buffer to string converting to utils
This commit is contained in:
parent
23a0768f8d
commit
d4f038f97b
@ -15,11 +15,7 @@
|
||||
var description = piskel.getDescriptor().description;
|
||||
var serialized = pskl.utils.Serializer.serializePiskel(piskel);
|
||||
|
||||
var serializedString = '';
|
||||
var uint16 = new Uint16Array(serialized);
|
||||
for (var i = 0, length = uint16.length; i < length; i++) {
|
||||
serializedString += String.fromCharCode(uint16[i]);
|
||||
}
|
||||
var serializedString = pskl.utils.convertBufferToString(serialized);
|
||||
|
||||
if (pskl.app.localStorageService.getPiskel(name)) {
|
||||
var confirmOverwrite = window.confirm('There is already a piskel saved as ' + name + '. Overwrite ?');
|
||||
|
@ -253,4 +253,26 @@ if (!Uint32Array.prototype.fill) {
|
||||
return string;
|
||||
};
|
||||
|
||||
ns.convertBufferToString = function (inputBuffer) {
|
||||
if (typeof inputBuffer.buffer !== 'undefined') {
|
||||
inputBuffer = inputBuffer.buffer;
|
||||
}
|
||||
|
||||
var buffer;
|
||||
|
||||
if (inputBuffer.byteLength % 2 === 1) {
|
||||
buffer = ArrayBuffer.transfer(inputBuffer, inputBuffer.byteLength + 1);
|
||||
} else {
|
||||
buffer = inputBuffer;
|
||||
}
|
||||
|
||||
var string = '';
|
||||
var uint16 = new Uint16Array(buffer);
|
||||
for (var i = 0, length = uint16.length; i < length; i++) {
|
||||
string += String.fromCharCode(uint16[i]);
|
||||
}
|
||||
|
||||
return string;
|
||||
};
|
||||
|
||||
})();
|
||||
|
Loading…
Reference in New Issue
Block a user