2013-03-13 109 views
2

我有一個.NET代碼處理我需要移植到WinRT的自定義Stream。其動機是,該應用程序讀取加密的文件(自定義Stream)。在完整的.NET我使用Stream在Windows應用商店應用中使用自定義流

var readFileStream = File.OpenRead(bookPath); 
var readDecryptedStream = new MyStream(password, readFileStream); 
//it is a zip file 
var readZipFile = new ZipFile(readDecryptedStream); 
//extract files from the zip file 

MyStream繼承和做一些編碼和解碼的讀/寫方法,完整的代碼是在這裏http://dl.dropbox.com/u/73642/mystream.cs。此代碼在.NET中正常工作。

我WinRT的實現是

var file =await ApplicationData.Current.LocalFolder.GetFileAsync(bookPath); //I copied the same file to Local folder 
var filestream = await file.OpenStreamForReadAsync(); 
var readDecryptedStream = new MyStream(password, readFileStream); 
ZipArchive z = new ZipArchive(readDecryptedStream , ZipArchiveMode.Read); 

這段代碼的問題是,new ZipArchive(readDecryptedStream , ZipArchiveMode.Read);從未完成讀取流。當我在MyStream讀取方法中設置一個斷點時,它始終被offset = 0調用(因此它永遠不會結束)。

當我使用未加密的文件與new ZipArchive(filestream , ZipArchiveMode.Read);比一切正常,因此問題必須是MyStream實施。

任何想法是什麼問題?自定義Stream在WinRT上需要不同的實現方式嗎?

+0

在WinRT實現中,您使用'readFlexiStream'來構建'ZipArchive'對象。 'readFlexiStream'從哪裏來?也許你應該使用'readDecryptedStream'來代替? – 2013-03-13 16:21:38

+0

@chuex a typo,sorry – 2013-03-13 22:39:40

+0

'offset == 0'絕對沒有錯。 'offset'指的是'緩衝區'而不是流。對於(int i = 0; i 2013-03-15 09:58:22

回答

0

我解決了它通過重新啓動我的電腦。這很奇怪,但有時所有的流,包括從ApplicatonData讀取文件只是停止工作,我不得不重新啓動計算機。這是一個真正的痛苦。