我试图将.7z文件的URI数据转换为.7z文件。我使用Create a file with data ur作为参考,但我必须做错事,因为我无法让它发挥作用。
以下是我所拥有的:
testData = {};
testData['application/x-7z-compressed'] = 'data:;base64,N3q8ryccAAQ9oftpCQoAAAAAAABaAAAAAAAAAEWEdGngCm8KAV0ARJQFxHon9vfuiY5QkIizqtVQOBGANPeca4QBmYkU+xl0vSo0unMUAXAps1eRa2pSM4v1BbfFdQTRV14VG+hh33uTXPUs2E/vn7WJG5j7l+CxeIBPtOphAZFAke0oMO6LvsQETmq6qQ4+tp0ATrrA7lF3XQLaKI5Pw4sjLzNDpWEUElVc3mZ4mb6D5zFyPy9lUxxTiLoBpF3XT192vk0iKjRUA3D1Fqvr8HBXNEQGIfWJVVEWsVigCSQo6X+DHusdwLvPK+132h9Gb2965peSZb1XZt/OlRqeXlqwDAkvH4D2/qHpXIqB+AfG92S81gfXLK48zk7K6FuEzkqcrpycJ/km12t0fxFrORAqqJRFU13FPgsMbcEIDZVaxGI66YOShpjL/pDyiqM5oUb8bJJfhiOPPHLEXi8vIYV5SYsbddoqeZja2FpgfIBY815QC5qDrVd6DnBaB5GnZGD3YfzDMMovm7dYkwD2xF+1hyu034NE1BzWomGRg1jlltO1TnxsPTPuE8MijBOczb9wP6d7/ezJH2hk52vRrrDQK4P6U6e1qwX9XMvNEkZgpu31iKlthMzDbf4Gun2lV3l3N+xDn6qLhXa6LNGC7/VnAXOF7eZTxJhtVtcMJZ8eal6AjLTf1olPZLnL4ZazhWeh7omtT45RIuJs58dPnJxz4zqC+B1t02wFNbyWDmtBLF9TTHuo0BHTysfkZpYngW2QZsRUG71tgSoDWBiQQ1mytXIKuIeyoYG4aRr6TYPSto89VV9X8keDn8APnUCa0p75eyL7U9ffAmgQt92zTvGH8NFgGUuMjfy/KJDZ7zdUXesGTcH1PZw0Yjly90v+RbmLVoyWIUGug8TAsttsFGhnau9kumoWDeJjr5f3Zx12pH80+YKsp9NeuFk/S8tb8VRZ1JgCCdlc8vOXzAl/ZS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Le820WKv9jYUPxlQ0PoQdVQOAMr8CqWmigi1/vGf1yeTJwryiVwKpyJm/zHVtf3W5d0TG+yRnMjhh2eJVkc9i+ff+NKkOHa/dh0ibilmqh0IGQjWCU5dVwxMCbjCn7UbBHrV0XeKmLfHZTevx6Fv0vM6MQt5UYPso5Baza/kBFX6Gxv6W3C8BVEsqA/SV7+kLtocYv/Zt9wguGmJ7jCdoPaeRqgCOkL5vHGo5sZHTWlUgPJ4uDhatbPRIch5FNAZD7tfc2VvgmsTZeI+65CJqgD7nDDZaBVwpLU7TOou14RSrNtrgT34BuO1Wpqer6kGZmR0OfjC80EFBCkUAAQQGAAEJigkABwsBAAEhIQEADIpwAAgKAZnuj2oAAAUBGQoAAAAAAAAAAAAAEREASQBSAEMALgBQAE4ARwAAABkCAAAUCgEAgBGSVy4Q0wEVBgEAIAAAAAAA';
function dataURIToBlob(dataURI) {
// Split the dataUri up into parts
// data:[<mediatype>][;<charset>],(data)
var parts = /data:([^;]+)(?:;([^,]+))?,(.+)/.exec(dataURI),
mime=parts[1],
charset=parts[2] || 'charset=US-ASCII',
encodedData=parts[3];
var data;
if (charset === 'base64') {
// If base64 convert to a Uint8 clamped array of character codes
var decodedData = atob(encodedData);
data = new Uint8Array(decodedData.length);
for (var i = 0; i < decodedData.length; i++) {
data[i] = decodedData.charCodeAt(i);
}
} else {
data = decodeURIComponent(encodedData);
}
return new Blob([data], {
type: mime
});
}
function createBlobURI() {
var blob = dataURIToBlob(testData);
var blobURI = URL.createObjectURL(blob);
blobURIAnchor.href = blobURI;
blobURIAnchor.innerHTML = blobURI;
blobURIAnchor.style.display = 'block';
blobURIAnchor.download = 'blob.' + blob.type.split('/')[1];
var blob = dataURIToBlob(testData);
var fso = new ActiveXObject("Scripting.FileSystemObject");
var fh = fso.OpenTextFile("test2.txt", 8, true);
fh.Write(blob);
fh.Close();
}
function insertTestData(mime) {
testData= testData[mime];
}
insertTestData('application/x-7z-compressed');
和
<button onclick='createBlobURI()'>Blob URI</button>
<a id="blobURIAnchor" href="#" style="display:none"></a>
按下按钮不执行任何操作。但是,当我使用图像文件时,它会成功创建blob。我该怎么办?可以通过浏览器手动转换,只需粘贴.7z的URI数据,单击另存为并命名为.7z。
答案 0 :(得分:0)
您的正则表达式不匹配data:;base64,N3...
它应该是data:application/x-7z-compressed;base64,N3...