-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from roofman2008/dev
Dev
- Loading branch information
Showing
13 changed files
with
167 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using System; | ||
using System.IO; | ||
using System.IO.Compression; | ||
using System.Text; | ||
|
||
namespace PaheScrapper.Helpers | ||
{ | ||
internal static class StringCompressor | ||
{ | ||
/// <summary> | ||
/// Compresses the string. | ||
/// </summary> | ||
/// <param name="text">The text.</param> | ||
/// <returns></returns> | ||
public static string CompressString(string text) | ||
{ | ||
byte[] buffer = Encoding.UTF8.GetBytes(text); | ||
var memoryStream = new MemoryStream(); | ||
using (var gZipStream = new GZipStream(memoryStream, CompressionMode.Compress, true)) | ||
{ | ||
gZipStream.Write(buffer, 0, buffer.Length); | ||
} | ||
|
||
memoryStream.Position = 0; | ||
|
||
var compressedData = new byte[memoryStream.Length]; | ||
memoryStream.Read(compressedData, 0, compressedData.Length); | ||
|
||
var gZipBuffer = new byte[compressedData.Length + 4]; | ||
Buffer.BlockCopy(compressedData, 0, gZipBuffer, 4, compressedData.Length); | ||
Buffer.BlockCopy(BitConverter.GetBytes(buffer.Length), 0, gZipBuffer, 0, 4); | ||
return Convert.ToBase64String(gZipBuffer); | ||
} | ||
|
||
/// <summary> | ||
/// Decompresses the string. | ||
/// </summary> | ||
/// <param name="compressedText">The compressed text.</param> | ||
/// <returns></returns> | ||
public static string DecompressString(string compressedText) | ||
{ | ||
byte[] gZipBuffer = Convert.FromBase64String(compressedText); | ||
using (var memoryStream = new MemoryStream()) | ||
{ | ||
int dataLength = BitConverter.ToInt32(gZipBuffer, 0); | ||
memoryStream.Write(gZipBuffer, 4, gZipBuffer.Length - 4); | ||
|
||
var buffer = new byte[dataLength]; | ||
|
||
memoryStream.Position = 0; | ||
using (var gZipStream = new GZipStream(memoryStream, CompressionMode.Decompress)) | ||
{ | ||
gZipStream.Read(buffer, 0, buffer.Length); | ||
} | ||
|
||
return Encoding.UTF8.GetString(buffer); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System.Net; | ||
using HtmlAgilityPack; | ||
using Newtonsoft.Json; | ||
|
||
namespace PaheScrapper.Helpers | ||
{ | ||
public static class WebErrorReporter | ||
{ | ||
public static void HttpError(WebResponse webResponse) | ||
{ | ||
LogWriter lw = new LogWriter("Http Dump: \n" + JsonConvert.SerializeObject(webResponse)); | ||
} | ||
|
||
public static void HtmlError(HtmlDocument htmlDocument) | ||
{ | ||
LogWriter lw = new LogWriter("Html Dump: \n" + StringCompressor.CompressString(htmlDocument.DocumentNode.InnerHtml)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.