Skip to content

Instantly share code, notes, and snippets.

@deejayy
Created July 22, 2024 11:51
Show Gist options
  • Save deejayy/bc25dc8768d974e90160057162739f96 to your computer and use it in GitHub Desktop.
Save deejayy/bc25dc8768d974e90160057162739f96 to your computer and use it in GitHub Desktop.
fileContainsPhrase-stream.js
const fs = require("fs");
console.log(Object.keys(process.memoryUsage()).join("\t"));
console.log(
Object.values(process.memoryUsage())
.map((value) => Math.round(value / 1e4) / 100)
.join("\t")
);
const fileContainsPhrase = async (filePath, phrase) => {
const stream = fs.createReadStream(filePath, "utf-8");
let prevChunk = "";
for await (const chunk of stream) {
const accumulatedChunks = prevChunk + chunk;
if (phrase.length > accumulatedChunks.length) {
throw new Error("Phrase too long to find");
}
if (accumulatedChunks.includes(phrase)) {
return true;
}
console.log(
Object.values(process.memoryUsage())
.map((value) => Math.round(value / 1e4) / 100)
.join("\t")
);
prevChunk = chunk;
}
};
fileContainsPhrase(
"pwned-passwords-update-1.txt",
"FFFFFE838DEBD519FC849F224C72C08AC4CD4D"
).then((result) => {
console.log(
Object.values(process.memoryUsage())
.map((value) => Math.round(value / 1e4) / 100)
.join("\t")
);
console.log(result);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment