所以我有一个应用程序,它触发一系列异步事件,然后将结果写入缓冲区.问题是我希望缓冲区同步写入(在产生异步进程的线程中)
骨架代码就是这样
let Session = NSURLSession.sharedSession()
let TheStack = [Structure]()
//This gets called asynchronously, e.g. in threads 3,4,5,6,7
func AddToStack(The Response) -> Void {
TheStack.insertAt(Structure(The Response), atIndex: 0))
if output.hasSpaceAvailable == true {
// This causes the stream event to be fired on mutliple threads
// This is what I want to call back into the original thread, e.g. in thread 2
self.stream(self.output, handleEvent: NSStreamEvent.hasSpaceAvailable)
}
}
// This is in the main loop, e.g. thread 2
func stream(aStream: NSStream, …Run Code Online (Sandbox Code Playgroud) 所以我正在尝试创建一个功能的基本原型。本质上,最终目标是接收 Base64 编码的字符串和支持的 mime 类型并生成文件并从 HTML 5 应用程序提供该文件。现在,我正在简单地获取一个文件,将其转换为 Blob,然后显示它,所有这些都是从内存中完成的。
var blobfile = atob(base64);
window.blobFromBlob = new Blob([binaryString], {
type: MIMEType
});
window.blobURL = URL.createObjectURL(window.blobFromBlob);
var a = "<a href=\"" + window.blobURL + "\">Binary Blob Link</a>";
document.getElementById('byte_content').innerHTML = a;
Run Code Online (Sandbox Code Playgroud)
我创建了一个JSFiddle来展示我遇到的问题。当我将 JPEG 放入其中,然后尝试提供它时,img 标签会显示损坏的图像。我从没想过 Base64 blob 能工作,但我确实希望二进制 blob 和来自 base 64 的 blob 能工作。
谁能看到我哪里出错了?
谢谢!
注意:我设法通过从 更改为 来显示二进制readAsBinaryString文件readAsArrayBuffer
atob注2:我开始怀疑它与和有关btoa