Conversion of data formats
Select source and destination data format.
Source contents
Source file
Destination contents
Convert procedure
// Prepare convert parameters
function args(type, next) {
var format = type.value.split('/');
format[2] = next;
return format;
}
// Decode data from source
function decode(format, param, ondata) {
if (format === 'Binary') {
var reader = new FileReader();
reader.onload = function(e) {
ondata(e.target.result);
}
reader.readAsArrayBuffer(fileSourceSelect.files[0]);
} else {
ondata(gostCrypto.coding[format].decode(source.textContent, param));
}
}
// Encode data to destination
function encode(format, param, data) {
if (format === 'Binary') {
saveAs(new Blob([data], {type: 'application/octet-stream'}), destFileName.value);
} else {
dest.textContent = gostCrypto.coding[format].encode(data, param);
}
}
// Execute procedure
decode.apply(this, args(fromtype, function(data) {
encode.apply(this, args(totype, data));
}));