Exemple #1
0
 public static Task TranscodeAsync <T>(
     string input,
     string output,
     ITimeSeriesDecoder <T> decoder,
     ITimeSeriesEncoder <T> encoder,
     Func <T, T> transform = null)
 {
     return(TranscodeAsync <T, T>(input, output, decoder, encoder, transform ?? (x => x)));
 }
Exemple #2
0
            public TimeSeriesChunk(InputChunk chunk, ITimeSeriesDecoder <T> decoder)
            {
                BeginPosition = chunk.BeginPosition;
                EndPosition   = chunk.EndPosition;
                _data         = Decode();

                IEnumerable <T> Decode()
                {
                    decoder.DecodePrimary(chunk, new DateTime(chunk.UserData.Long0, DateTimeKind.Utc), out T val);
                    yield return(val);

                    while (decoder.DecodeSecondary(chunk, out val))
                    {
                        yield return(val);
                    }
                }
            }
Exemple #3
0
        // Reads all chunks from the ChunkIO file named `input`, decodes their content with `decoder`,
        // transforms records with `transform`, encodes them with `encoder` and appends to the ChunkIO
        // file named `output`.
        //
        // The output ChunkIO file is written with default WriterOptions. Some input chunks may get
        // merged but no chunks get split.
        public static async Task TranscodeAsync <T, U>(
            string input,
            string output,
            ITimeSeriesDecoder <T> decoder,
            ITimeSeriesEncoder <U> encoder,
            Func <T, U> transform)
        {
            using (var reader = new TimeSeriesReader <T>(input, decoder)) {
                var writer = new TimeSeriesWriter <U>(output, encoder);
                try {
                    long len = await reader.FlushRemoteWriterAsync(flushToDisk : false);

                    await reader.ReadAfter(DateTime.MinValue, 0, len).ForEachAsync(async(IDecodedChunk <T> c) => {
                        await writer.WriteBatchAsync(c.Select(transform));
                    });
                } finally {
                    await writer.DisposeAsync();
                }
            }
        }
Exemple #4
0
 // The file must exist and be readable. There is no explicit file format check. If the file
 // wasn't created by ChunkWriter, all its content will be simply skipped without any errors.
 //
 // You can read the file even while there is an active TimeSeriesWriter writing to it. You
 // might want to use FlushRemoteWriterAsync() in this case.
 //
 // Takes ownership of the decoder. TimeSeriesReader.Dispose() will dispose it.
 public TimeSeriesReader(string fname, ITimeSeriesDecoder <T> decoder)
 {
     Decoder = decoder ?? throw new ArgumentNullException(nameof(decoder));
     _reader = new BufferedReader(fname);
 }