public void OpenReadTestGZipSmallRead()
        {
            using (var res = new ImprovedStream(new SourceAccess(UnitTestInitializeCsv.GetTestPath("BasicCsV.txt.gz"), true)))
            {
                Assert.IsNotNull(res);
                var result1 = new byte[2048];
                using (var reader = new BinaryReader(res))
                {
                    reader.Read(result1, 0, result1.Length);
                }

                // should return to teh start
                res.Seek(0, SeekOrigin.Begin);
                var result2 = new byte[2048];
                using (var reader = new BinaryReader(res))
                {
                    reader.Read(result2, 0, result2.Length);
                }

                Assert.AreEqual(result1[0], result2[0]);
                Assert.AreEqual(result1[1], result2[1]);
                Assert.AreEqual(result1[2], result2[2]);
                Assert.AreEqual(result1[3], result2[3]);
                Assert.AreEqual(result1[4], result2[4]);
                Assert.AreEqual(result1[5], result2[5]);
            }
        }
        public void OpenReadTestGZipLargeRead()
        {
            using (var res = new ImprovedStream(new SourceAccess(UnitTestInitializeCsv.GetTestPath("Larger.json.gz"), true)))
            {
                Assert.IsNotNull(res);

                var result1 = new byte[10000];

                // read a potion that is larger than the buffered stream
                using (var reader = new BinaryReader(res))
                {
                    reader.Read(result1, 0, result1.Length);
                }

                // should return to the start
                res.Seek(0, SeekOrigin.Begin);
                var result2 = new byte[10000];
                using (var reader = new BinaryReader(res))
                {
                    reader.Read(result2, 0, result2.Length);
                }

                Assert.AreEqual(result1[0], result2[0]);
                Assert.AreEqual(result1[1], result2[1]);
                Assert.AreEqual(result1[2], result2[2]);
                Assert.AreEqual(result1[3], result2[3]);
                Assert.AreEqual(result1[4], result2[4]);
                Assert.AreEqual(result1[5], result2[5]);
            }
        }
Ejemplo n.º 3
0
        public async System.Threading.Tasks.Task AnalyseStreamAsyncFile()
        {
            var stream = FileSystemUtils.OpenRead(UnitTestInitializeCsv.GetTestPath("BasicCSV.txt"));

            ICollection <IColumn> determinedColumns;

            // Not closing the stream

            using (IProcessDisplay process = new CustomProcessDisplay(UnitTestInitializeCsv.Token))
            {
                using (var impStream = new ImprovedStream(stream))
                {
                    var result = await impStream.GetDetectionResult("stream", process, false, true, true, true, true, true, false);

                    impStream.Seek(0, System.IO.SeekOrigin.Begin);

                    using (var reader = new CsvFileReader(impStream, result.CodePageId, result.SkipRows, result.HasFieldHeader,
                                                          new ColumnCollection(), TrimmingOption.Unquoted, result.FieldDelimiter, result.FieldQualifier,
                                                          result.EscapeCharacter, 0, false, false, result.CommentLine, 0, true, string.Empty, string.Empty,
                                                          string.Empty, true, false, true, false, false, false, false, false, false, true, true))
                    {
                        await reader.OpenAsync(process.CancellationToken);

                        var(info, columns) = await reader.FillGuessColumnFormatReaderAsyncReader(new FillGuessSettings(),
                                                                                                 new ColumnCollection(), false, true, "null", process.CancellationToken);

                        determinedColumns = columns.ToList();
                        Assert.AreEqual(6, determinedColumns.Count(), "Recognized columns");
                        Assert.AreEqual(6, info.Count, "Information Lines");
                    }

                    impStream.Seek(0, SeekOrigin.Begin);

                    using (var reader = new CsvFileReader(impStream, result.CodePageId, result.SkipRows, result.HasFieldHeader,
                                                          determinedColumns, TrimmingOption.Unquoted, result.FieldDelimiter, result.FieldQualifier,
                                                          result.EscapeCharacter, 0, false, false, result.CommentLine, 0, true, string.Empty, string.Empty,
                                                          string.Empty, true, false, true, false, false, false, false, false, false, true, true))
                    {
                        await reader.OpenAsync(process.CancellationToken);

                        Assert.AreEqual(6, reader.FieldCount);
                    }
                }
            }
        }
        public void OpenReadTestZipSmallRead()
        {
            var sourceAccess = new SourceAccess(UnitTestInitializeCsv.GetTestPath("AllFormatsPipe.zip"), true);

            // opeing without IdentifierInContainer should return teh first file entry
            using (var res = new ImprovedStream(sourceAccess))
            {
                Assert.AreEqual("AllFormatsPipe.txt", sourceAccess.IdentifierInContainer);
                Assert.IsNotNull(res);
                var result1 = new byte[2048];
                using (var reader = new BinaryReader(res))
                {
                    reader.Read(result1, 0, result1.Length);
                }

                // should return to teh start
                res.Seek(0, SeekOrigin.Begin);
                var result2 = new byte[2048];
                using (var reader = new BinaryReader(res))
                {
                    reader.Read(result2, 0, result2.Length);
                }

                Assert.AreEqual(result1[0], result2[0]);
                Assert.AreEqual(result1[1], result2[1]);
                Assert.AreEqual(result1[2], result2[2]);
                Assert.AreEqual(result1[3], result2[3]);
                Assert.AreEqual(result1[4], result2[4]);
                Assert.AreEqual(result1[5], result2[5]);
            }

            // now sourceAccess.IdentifierInContainer is set,
            using (var res = new ImprovedStream(sourceAccess))
            {
                Assert.IsNotNull(res);
            }
        }