Example #1
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="LazyCsvFile"/> class.
        /// </summary>
        /// <param name="file">The file containing the CSV to read.</param>
        /// <param name="lineSlack">The amount of slack space for each line.</param>
        /// <param name="options">The reader options.</param>
        public LazyCsvFile(string file, int lineSlack, LazyCsvFileOptions options)
        {
            File      = file;
            LineSlack = lineSlack;
            Options   = options;

            using (var csv = new CsvStreamReader(file, options))
            {
                HeaderDictionary = csv.StreamReader.ReadLine().Split(',')
                                   .Select((x, i) => new KeyValuePair <string, int>(x, i))
                                   .ToDictionary(x => x.Key, x => x.Value);
            }
        }
Example #2
0
            public CsvStreamReader(string file, LazyCsvFileOptions options)
            {
                FileStream = new FileStream(file, FileMode.Open);

                if (options.HasFlag(LazyCsvFileOptions.ForceGZip) || IsGZipped(FileStream))
                {
                    GZipStream   = new GZipStream(FileStream, CompressionMode.Decompress);
                    StreamReader = new StreamReader(GZipStream);
                }
                else
                {
                    StreamReader = new StreamReader(FileStream);
                }
            }
Example #3
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="LazyCsvFile"/> class.
 /// </summary>
 /// <param name="file">The file containing the CSV to read.</param>
 /// <param name="options">The reader options.</param>
 public LazyCsvFile(string file, LazyCsvFileOptions options)
     : this(file, 0, options)
 {
 }