-
Notifications
You must be signed in to change notification settings - Fork 0
/
StorageHelper.cs
93 lines (82 loc) · 2.47 KB
/
StorageHelper.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
using System;
using System.IO;
using System.Collections.Generic;
namespace wpscanauto{
public class StorageHelper{
public enum RepoName{
SHELL_TEMPLATE = 1,
TWEET_CONTENTS_BLACKLIST = 2,
TWITTER_FOLLOWERS = 3,
TWITTER_TAGLIST = 4,
TWITTER_PASTE_DUMPERS = 5,
EMAIL_OFFENCES = 6,
GITHUB_OFFENCES = 7,
GITHUB_BLACKLIST = 8,
WORDPRESS_SCANNER_DATA =9
}
private static Dictionary<RepoName,string> RepositoryPaths = new Dictionary<RepoName, string>(){
{RepoName.SHELL_TEMPLATE,"shell.cs"},
{RepoName.TWEET_CONTENTS_BLACKLIST,"blackList.txt"},
{RepoName.TWITTER_FOLLOWERS,"followedList.txt"},
{RepoName.TWITTER_PASTE_DUMPERS,"downloadFollowList.txt"},
{RepoName.TWITTER_TAGLIST,"streamTagList.txt"},
{RepoName.EMAIL_OFFENCES,"offencelist.txt"},
{RepoName.GITHUB_OFFENCES, "github-offences.txt"},
{RepoName.GITHUB_BLACKLIST,"github-blacklist.txt"},
{RepoName.WORDPRESS_SCANNER_DATA,"wordpress-urls-and-users.txt"}
};
public StorageHelper(){
}
#region READ TEXT files
public static string ReadToEnd(string filename){
using (StreamReader reader = new StreamReader (filename)) {
return reader.ReadToEnd ();
}
}
public static string ReadToEnd(RepoName repoName){
return ReadToEnd (RepositoryPaths [repoName]);
}
public static List<string> ReadLines(RepoName repoName){
List<string> rows = new List<string> ();
using (StreamReader reader = new StreamReader (RepositoryPaths [repoName])) {
string row = reader.ReadLine ();
while (row != null && row != "") {
rows.Add (row.Trim());
row = reader.ReadLine ();
}
}
return rows;
}
#endregion
#region WRITE TEXT files
public static void WriteLines(RepoName repoName, List<string> lines){
using (StreamWriter writer = new StreamWriter (RepositoryPaths[repoName])) {
foreach (string line in lines) {
writer.WriteLine (line.Trim());
}
}
}
#endregion
#region READ BINARY files
public static byte[] ReadBinaryData(string filename)
{
const int CHUNK_SIZE = 1024;
List<byte> bytes = new List<byte>();
using (FileStream fs = new FileStream(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read))
{
using (System.IO.BinaryReader br = new System.IO.BinaryReader(fs))
{
byte[] chunk;
chunk = br.ReadBytes(CHUNK_SIZE);
while (chunk.Length > 0)
{
bytes.AddRange(chunk);
chunk = br.ReadBytes(CHUNK_SIZE);
}
}
}
return bytes.ToArray();
}
#endregion
}
}