public static Stream ToTextStream(this Stream stream, SRCCompatibilityMode srcCompatibilityMode) { if (srcCompatibilityMode.HasFlag(SRCCompatibilityMode.Read)) { // XXX あまりいい同期化ではないはず // Streamには同期メソッドがあるはずなので、同期処理したいなら同期メソッドを一貫して使うメソッドにするのがよさそう return(Task.Run(() => stream.ToUTF8Async()).Result); } else { return(stream); } }
public FileHandle(int handle, Stream stream, SafeOpenMode mode, SRCCompatibilityMode srcCompatibilityMode) { Handle = handle; Stream = stream; if (mode == SafeOpenMode.Read) { Reader = new StreamReader(stream.ToTextStream(srcCompatibilityMode)); } else { Writer = new StreamWriter(stream, srcCompatibilityMode.HasFlag(SRCCompatibilityMode.Write) ? Encoding.GetEncoding(932) : Encoding.UTF8); } }