我正在尝试实施StreamSocket通信,服务器正在向我发送一个" .zip"文件在byte [] chuncks中。看起来我的内存中的byte []很好(字节数与服务器中的原始.zip文件相同)但是当我将这些字节保存在文件中时,解压缩程序说它已经损坏了' #39;
我尝试了几种选择,但没有一种适合我:
1
var file = await StorageFile.CreateFileAsync();
using(var stream = await file.OpenStreamForWriteAsync())
{
stream.Write(myBytes, ...);
}
2
var file = await StorageFile.CreateFileAsync();
await FileIO.WriteBytesAsync(file, myBytes);
3
var file = await StorageFile.CreateFileAsync();
using (var fileStream = await file.OpenStreamForWriteAsync())
{
var sessionData = new MemoryStream(myBytes);
sessionData.Seek(0, SeekOrigin.Begin);
await sessionData.CopyToAsync(fileStream);
}
4
var file = await StorageFile.CreateFileAsync();
using (var writer = new BinaryWriter(await file.OpenStreamForWriteAsync())
{
writer.WriteBytes(myBytes);
}
如果有人有新想法,请分享。
问候。