@@ -2,14 +2,22 @@ import { createInterface } from 'readline'
22import { createWriteStream , createReadStream } from 'fs'
33
44export class Blacklist {
5+ private readonly filePath ?: string
6+
7+ constructor ( filePath ?: string ) {
8+ this . filePath = filePath
9+ }
10+
511 /**
612 * Add value to a file path
713 *
814 * @param value The value to be add
915 * @param filePath The file path to the blacklist
1016 * @return void
1117 */
12- async add ( value : string , filePath : string ) : Promise < void > {
18+ async add ( value : string , filePath ?: string ) : Promise < void > {
19+ filePath = filePath || this . filePath
20+
1321 return new Promise ( ( resolve , reject ) => {
1422 const stream = createWriteStream ( filePath , { flags : 'a' } )
1523
@@ -31,6 +39,8 @@ export class Blacklist {
3139 * @return string|null The value found or null
3240 */
3341 async find ( value : string , filePath : string ) : Promise < string | null > {
42+ filePath = filePath || this . filePath
43+
3444 const stream = createReadStream ( filePath )
3545
3646 const lines = createInterface ( {
@@ -57,6 +67,8 @@ export class Blacklist {
5767 * @return void The value found or null
5868 */
5969 async remove ( value : string , filePath : string ) : Promise < void > {
70+ filePath = filePath || this . filePath
71+
6072 return new Promise ( ( resolve , reject ) => {
6173 const readStream = createReadStream ( filePath )
6274
0 commit comments