public void TarFileReadTest() { string fileName = Path.Combine(Directory.GetCurrentDirectory(), "sample.tar"); using (var tr = new TarReader(fileName)) { Assert.IsTrue(tr.Files.Count == 13); Assert.IsTrue(tr.Files[0].FileSizeInBytes == 629); Assert.IsTrue(tr.Files[0].FileName == "BmpReader.cs"); Assert.IsTrue(tr.Files[12].FileSizeInBytes == 4078); Assert.IsTrue(tr.Files[12].FileName == "XSub.cs"); } }
/// <summary> /// The wc_ download data completed. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The e. /// </param> private void wc_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e) { if (e.Error != null) { MessageBox.Show(Configuration.Settings.Language.GetTesseractDictionaries.DownloadFailed); this.DialogResult = DialogResult.Cancel; return; } string dictionaryFolder = Configuration.TesseractDataFolder; if (!Directory.Exists(dictionaryFolder)) { Directory.CreateDirectory(dictionaryFolder); } int index = this.comboBoxDictionaries.SelectedIndex; var tempFileName = Path.GetTempFileName() + ".tar"; using (var ms = new MemoryStream(e.Result)) using (var fs = new FileStream(tempFileName, FileMode.Create)) using (var zip = new GZipStream(ms, CompressionMode.Decompress)) { byte[] buffer = new byte[1024]; int nRead; while ((nRead = zip.Read(buffer, 0, buffer.Length)) > 0) { fs.Write(buffer, 0, nRead); } } using (var tr = new TarReader(tempFileName)) { foreach (var th in tr.Files) { string fn = Path.Combine(dictionaryFolder, Path.GetFileName(th.FileName.Trim())); th.WriteData(fn); } } File.Delete(tempFileName); this.Cursor = Cursors.Default; this.labelPleaseWait.Text = string.Empty; this.buttonOK.Enabled = true; this.buttonDownload.Enabled = true; this.comboBoxDictionaries.Enabled = true; MessageBox.Show(string.Format(Configuration.Settings.Language.GetDictionaries.XDownloaded, this.comboBoxDictionaries.Items[index])); }