Stream() public static method

public static Stream ( object stream ) : void
stream object
return void
コード例 #1
0
        /// <summary>
        ///     Loads a .torrent from the supplied stream
        /// </summary>
        /// <param name="stream">The stream containing the data to load</param>
        /// <returns></returns>
        public static Torrent Load(Stream stream)
        {
            Check.Stream(stream);

            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            return(Load(stream, ""));
        }
コード例 #2
0
        /// <summary>
        ///     Loads a .torrent from the supplied stream. A return value indicates
        ///     whether the operation was successful.
        /// </summary>
        /// <param name="stream">The stream containing the data to load</param>
        /// <param name="torrent">If the loading was succesful it is assigned the Torrent</param>
        /// <returns>True if successful</returns>
        public static bool TryLoad(Stream stream, out Torrent torrent)
        {
            Check.Stream(stream);

            try
            {
                torrent = Load(stream);
            }
            catch
            {
                torrent = null;
            }

            return(torrent != null);
        }
コード例 #3
0
        /// <summary>
        ///     Called from either Load(stream) or Load(string).
        /// </summary>
        /// <param name="stream"></param>
        /// <param name="path"></param>
        /// <returns></returns>
        private static Torrent Load(Stream stream, string path)
        {
            Check.Stream(stream);
            Check.Path(path);

            try
            {
                var t = LoadCore((BEncodedDictionary)BEncodedValue.Decode(stream));
                t.TorrentPath = path;
                return(t);
            }
            catch (BEncodingException ex)
            {
                throw new TorrentException("Invalid torrent file specified", ex);
            }
        }