/// <summary>
        /// Load a FetchCompleteEventArgs from a stream
        /// </summary>
        /// <param name="stream">Stream to load from</param>
        /// <returns>FetchCompleteEventArgs loaded</returns>
        public static FetchCompleteEventArgs LoadFetchResult(Stream stream)
        {
            // The streamreader internal cache will consume the binary payload
            BinaryReader br = new BinaryReader(stream);
            // read link
            var link = readLinesBlock("LINK", br);
            // read link
            var req = readLinesBlock("REQ-HDR", br);
            // read link
            var resp = readLinesBlock("RES-HDR", br);

            byte[] bytes = readToEnd(br);

            return(new FetchCompleteEventArgs(Link.LoadLink(link), bytes, HeaderCollection.LoadHeader(req), HeaderCollection.LoadHeader(resp)));
        }
示例#2
0
 /// <summary>
 /// Saves the Header in a line-based http-like format
 /// </summary>
 /// <param name="header">Link to be saved</param>
 /// <returns>Header</returns>
 public static IEnumerable <string> SaveHeader(HeaderCollection header)
 {
     return(header.dicValues.Select(o => $"{o.Key}: {o.Value}"));
 }
 /// <summary>
 /// Constructs a new FetchCompleteEventArgs
 /// </summary>
 public FetchCompleteEventArgs(Link current, byte[] result, HeaderCollection requestHeaders, HeaderCollection responseHeaders)
 {
     this.Link            = current;
     this.Result          = result;
     this.RequestHeaders  = requestHeaders;
     this.ResponseHeaders = responseHeaders;
 }