Author: alanmc
Date: 2006-09-10 12:25:12 -0400 (Sun, 10 Sep 2006)
New Revision: 65177
Modified:
branches/BitSharp/bitsharp/src/MonoTorrent.Common/BEncode/BEncode.cs
Log:
Added support for decoding a BEncodedValue starting at a specific offset in a
byte[]
Modified: branches/BitSharp/bitsharp/src/MonoTorrent.Common/BEncode/BEncode.cs
===================================================================
--- branches/BitSharp/bitsharp/src/MonoTorrent.Common/BEncode/BEncode.cs
2006-09-10 16:09:19 UTC (rev 65176)
+++ branches/BitSharp/bitsharp/src/MonoTorrent.Common/BEncode/BEncode.cs
2006-09-10 16:25:12 UTC (rev 65177)
@@ -67,7 +67,39 @@
}
+
/// <summary>
+ /// Decode BEncoded data in the given byte array
+ /// </summary>
+ /// <param name="buffer">The byte array containing the BEncoded
data</param>
+ /// <param name="offset">The offset at which the data starts at</param>
+ /// <param name="length">The number of bytes to be decoded</param>
+ /// <returns>BEncodedValue containing the data that was in the
byte[]<returns>
+ public static IBEncodedValue Decode(byte[] buffer, int offset, int
length)
+ {
+ using (MemoryStream stream = new MemoryStream(buffer, offset,
length))
+ using (BinaryReader reader = new BinaryReader(stream,
Encoding.UTF8))
+ return Decode(reader);
+ }
+
+
+ /// <summary>
+ /// Decode BEncoded data in the given byte array
+ /// </summary>
+ /// <param name="buffer">The byte array containing the BEncoded
data</param>
+ /// <param name="offset">The offset at which the data starts at</param>
+ /// <param name="length">The number of bytes to be decoded</param>
+ /// <param name="e">The encoding of the data</param>
+ /// <returns>BEncodedValue containing the data that was in the
byte[]<returns>
+ public static IBEncodedValue Decode(byte[] buffer, int offset, int
length, Encoding e)
+ {
+ using (MemoryStream stream = new MemoryStream(buffer, offset,
length))
+ using (BinaryReader reader = new BinaryReader(stream, e))
+ return Decode(reader);
+ }
+
+
+ /// <summary>
/// Decode BEncoded data in the given stream
/// </summary>
/// <param name="stream">The stream containing the BEncoded
data</param>
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches