[Modify] Add an extension method
This commit is contained in:
parent
1d645fe8f0
commit
9d514440bf
@ -296,6 +296,44 @@ namespace WebSocketSharp
|
|||||||
destination.Write (buff, 0, nread);
|
destination.Write (buff, 0, nread);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static void CopyToAsync (
|
||||||
|
this Stream source,
|
||||||
|
Stream destination,
|
||||||
|
int bufferLength,
|
||||||
|
Action completed,
|
||||||
|
Action<Exception> error)
|
||||||
|
{
|
||||||
|
var buff = new byte[bufferLength];
|
||||||
|
|
||||||
|
AsyncCallback callback = null;
|
||||||
|
callback = ar => {
|
||||||
|
try {
|
||||||
|
var nread = source.EndRead (ar);
|
||||||
|
if (nread <= 0) {
|
||||||
|
if (completed != null)
|
||||||
|
completed ();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
destination.Write (buff, 0, nread);
|
||||||
|
source.BeginRead (buff, 0, bufferLength, callback, null);
|
||||||
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
if (error != null)
|
||||||
|
error (ex);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
source.BeginRead (buff, 0, bufferLength, callback, null);
|
||||||
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
if (error != null)
|
||||||
|
error (ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
internal static byte[] Decompress (this byte[] data, CompressionMethod method)
|
internal static byte[] Decompress (this byte[] data, CompressionMethod method)
|
||||||
{
|
{
|
||||||
return method == CompressionMethod.Deflate
|
return method == CompressionMethod.Deflate
|
||||||
|
Loading…
Reference in New Issue
Block a user