私はGzipをサーバー上に作成し、WebClientクラスを使用してクライアントにダウンロードします。解凍しようとすると、Magic Numberが見つからないというエラーメッセージが表示されます。私はGZipStreamクラスとこれを解決するICSharpLibメソッドの両方を試したので、私は迷っています。Gzipのマジックナンバーを解決する方法がありません
WebClient経由でダウンロードするステップ(DownloadDataを使用してデータをバイト[]として返す)を省略すると、圧縮/解凍が機能するため、データが切り捨てられたり破損したりするという問題があると仮定できますどのように圧縮されたデータなので、これをデバッグする方法がわかりません。ここで
は、問題のある部分であるように思わコードスニペットです:
byte[] response
try {
response = client.DownloadData(Constants.GetSetting("SyncServer"));
} catch {
MessageBox.Show("There was a problem synchronizing the data. Please try verify the supplied credentials or try again later.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
int rows = SQLiteAPI.ImportStatHistoryXML(CurrentUser.User, myCampus, Convert.ToBase64String(response));
public static int ImportStatHistoryXML(Person tempPerson, Campus tempCampus, string xmlFile) {
byte[] encryptedFile = Convert.FromBase64String(xmlFile);
MemoryStream memStream = new MemoryStream(encryptedFile);
memStream.ReadByte();
GZipInputStream stream = new GZipInputStream(memStream);
MemoryStream memory = new MemoryStream();
byte[] writeData = new byte[4096];
int size;
while (true) {
size = stream.Read(writeData, 0, writeData.Length);
if (size > 0) {
memory.Write(writeData, 0, size);
} else {
break;
}
}
stream.Close();
memory.Position = 0;
StreamReader sr = new StreamReader(memory);
string decompressed = sr.ReadToEnd();
DataSet tempSet = new DataSet();
StringReader xmlReader = new StringReader(decompressed);
tempSet.ReadXml(xmlReader);
DataTable statTable = tempSet.Tables["Stats"];
...more unrelated processing of the table
}
任意の助けをいただければ幸いです。 P.S.私は、Base64文字列を使ってウェブを行き来することができます。これは実際には、デスクトップアプリとWebサービスの間でWebリクエストや応答を行っていないので、私が戸惑っている部分です。
あなたはそうです。申し訳ありませんが、私が欠けていたものを整えることができるかどうかを確認する最後の溝の努力を試みていました。 – Jared
ありがとうございます。コードはもっと理にかなっていますが、私の質問には答えられませんでした。 –
私はbase64エンコードされた文字列を持っていますか?それはうまくいかないでしょうか?どのようにGzip'edデータをWebサービスとの間でやりとりしますか? – Jared