问题描述
没有人知道一个合成流溶液中,以一个MemoryStream将预加载一个流的第一部分,并保持剩余的原始流时以后的零件需要作为必要的,这将被访问的
Does anyone know of a composite stream solution that will pre-load the first portion of a Stream in to a MemoryStream and keep the remainder as the original Stream which will be accessed when subsequent parts are required as necessary?
我可以想象一些包装类将实现流接口和透明地兼顾取决于哪一部分被访问两个流之间的访问。
I should imagine some wrapper class would implement the Stream interface and transparently juggle the access between the two streams depending upon which part is accessed.
我希望这是一个解决方案,有人可能以前解决,也许优化阅读了大量的FileStream性能。
I'm hoping this is a solution someone may have solved before, maybe to optimize performance of reading a large FileStream.
在我的情况下,我想避开一款Windows Phone 8的错误从SD卡读取大文件。我试图环绕该问题的更多细节在这个答案提供:
In my case I'm trying to get around a Windows Phone 8 bug reading large files from the SD card. More detail of the issue I'm trying to circumnavigate is provided in this answer:http://stackoverflow.com/a/17355068/250254
推荐答案
有没有可以用一个MemoryStream来解决这个bug任何合理的方式,你会在第一OutOfMemoryException异常摔倒。让我们关注了一下这个错误,我会简化代码位,使其可读的:
There isn't any reasonable way you can use a MemoryStream to work around the bug, you'll fall over on OutOfMemoryException first. Let's focus a bit on the bug, I'll simplify the code a bit to make it readable:
DistanceToMove = (offset & 0xffffffff00000000L) >> 32;
DistanceToMoveHigh = offset & 0xffffffffL;
SetFilePointer(this.m_handle, lDistanceToMove, ref lDistanceToMoveHigh, begin);
微软程序员意外交换的低值和高值。好了,所以你能撤消错误。自己掉他们如此的bug交换他们回到你想要的方式:
The Microsoft programmer accidentally swapped the low and high values. Well, so can you to undo the bug. Swap them yourself so the bug swaps them back the way you want it:
public static void SeekBugWorkaround(Stream stream, long offset, SeekOrigin origin) {
ulong uoffset = (ulong)offset;
ulong fix = ((uoffset & 0xffffffffL) << 32) | ((uoffset & 0xffffffff00000000L) >> 32);
stream.Seek((long)fix, origin);
}
在情况下,它需要说,它显然不,你必须指望微软最终修复这个bug。很难预测时的下一个点释放,赌博。有一些优势可以自动检测这一点,尽管它并不清楚微软会做,因为这个错误是如此的突破。寻求的返回值()和Position属性返回值从相同的错误受到影响。因此,寻求位置1和验证获得1回。
In case it needs to be said, it apparently does, you do have to count on Microsoft eventually fixing this bug. Hard to predict when so gamble on the next point release. There are some odds you can auto-detect this, albeit that it isn't obvious what Microsoft is going to do since this bug is so breaking. The return value of Seek() as well as the Position property return value suffer from the same bug. So seek to position 1 and verify that you get 1 back.
这篇关于复合流包装提供部分的MemoryStream和完整的原始流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!