Example #1
0
        /// <summary>
        /// エントリーポイント
        /// </summary>
        /// <param name="path">ファイルへのパス。なし、もしくは`-`の場合はSTDINから読み込む</param>
        /// <param name="decode">trueのときデコード動作をする</param>
        /// <param name="inputEncoding">入力ストリームのエンコーディング</param>
        /// <param name="outputEncoding">出力ストリームのエンコーディング</param>
        /// <returns>ステータスコード</returns>
        public int Run(
            [Option(0, "FILE")] string path     = "-",
            [Option("d", "decode")] bool decode = false,
            [Option("f", "input encoding")] StreamEncoding inputEncoding   = StreamEncoding.system,
            [Option("t", "output encoding")] StreamEncoding outputEncoding = StreamEncoding.system
            )
        {
            var iEncoding = GetEncoding(inputEncoding);
            var oEncoding = GetEncoding(outputEncoding);

            using var oStream = new StreamWriter(Console.OpenStandardOutput(), oEncoding);

            using var stream = GetStream(path);
            if (decode)
            {
                try {
                    var decoder = new Wbase59Decoder(stream, iEncoding);
                    oStream.Write(oEncoding.GetString(decoder.Decode().ToArray()));
                }
                catch (InvalidNabeFormatException e) {
                    LogError("ナベストリーム解析中にエラーが発生しました");
                    LogError(e.Message);
                    return(1);
                }
                catch (InvalidNabeIvsException e) {
                    LogError("不正なIvsです");
                    LogError(e.Message);
                    return(1);
                }
                catch (ParityNabeCheckFailedException e) {
                    LogError(e.Message);
                    return(1);
                }
                catch (Exception e) {
                    LogError(e);
                    return(1);
                }
            }
            else
            {
                try {
                    var encoder = new Wbase59Encoder(stream, iEncoding);
                    foreach (var nabe in encoder.Encode())
                    {
                        oStream.Write(new UnicodeEncoding(true, false).GetString(nabe.GetSpan()));
                    }

                    oStream.Flush();
                }
                catch (InvalidNabeFormatException e) {
                    LogError(e);
                    return(1);
                }
            }

            return(0);
        }
Example #2
0
        private static async Task WriteStringAsync(string outString, Stream stream)
        {
            var data       = StreamEncoding.GetBytes(outString);
            var dataLength = data.Length;
            var chunkCount = dataLength / MaxChunkDataSize + (dataLength % MaxChunkDataSize > 0 ? 1 : 0);

            await WriteBundleHeaderAsync(stream, dataLength, chunkCount);

            var chunkOffset = 0;

            while (chunkOffset < dataLength)
            {
                chunkOffset = await WriteChunkAsync(stream, data, dataLength, chunkOffset);
            }
        }
Example #3
0
        protected static async Task <string> ReadStringAsync(Stream stream)
        {
            var bundleParams = await ReadBundleHeaderAsync(stream);

            if (!bundleParams.Success)
            {
                throw new Exception("Invalid header signature");
            }
            var buffer      = new byte[bundleParams.DataLength];
            var chunkOffset = 0;

            for (var i = 0; i < bundleParams.ChunkCount; i++)
            {
                chunkOffset = await ReadChunkAsync(stream, buffer, chunkOffset);
            }
            return(StreamEncoding.GetString(buffer));
        }
Example #4
0
 /// <summary>
 /// Constructs a new WebcastStream object
 /// </summary>
 /// <param name="uri">The URI of the stream</param>
 /// <param name="encoding">The encoding of the stream</param>
 public WebcastStream(Uri uri, StreamEncoding encoding)
 {
     this.Uri = uri;
     this.Encoding = encoding;
 }
 public StreamInfo(Uri uri, StreamEncoding encoding)
 {
     this.Uri = uri;
     this.Encoding = encoding;
 }
Example #6
0
 /// <summary>
 /// Constructs a new WebcastStream object
 /// </summary>
 /// <param name="uri">The URI of the stream</param>
 /// <param name="encoding">The encoding of the stream</param>
 public WebcastStream(Uri uri, StreamEncoding encoding)
 {
     this.Uri      = uri;
     this.Encoding = encoding;
 }