Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: runk/node-maxmind
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v4.3.22
Choose a base ref
...
head repository: runk/node-maxmind
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v4.3.23
Choose a head ref
  • 11 commits
  • 4 files changed
  • 2 contributors

Commits on Oct 1, 2024

  1. chore(deps): update dependency semantic-release to v24.1.2

    renovate[bot] committed Oct 1, 2024

    Verified

    This commit was signed with the committer’s verified signature.
    slawekjaranowski Slawomir Jaranowski
    Copy the full SHA
    6a706ad View commit details
  2. chore(deps): update dependency sinon to v18.0.1

    renovate[bot] committed Oct 1, 2024
    Copy the full SHA
    a0b0558 View commit details
  3. chore(deps): update dependency typescript to v5.6.2

    renovate[bot] committed Oct 1, 2024
    Copy the full SHA
    a83e803 View commit details
  4. chore(deps): update dependency sinon to v19

    renovate[bot] committed Oct 1, 2024
    Copy the full SHA
    8826e68 View commit details

Commits on Nov 1, 2024

  1. chore(deps): update dependency @types/jest to v29.5.14

    renovate[bot] committed Nov 1, 2024
    Copy the full SHA
    0ab5fcb View commit details
  2. chore(deps): update dependency typescript to v5.6.3

    renovate[bot] committed Nov 1, 2024
    Copy the full SHA
    ad0b5ad View commit details
  3. chore(deps): update dependency @types/node to v20.17.5 (#869)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    renovate[bot] authored Nov 1, 2024
    Copy the full SHA
    68bb921 View commit details
  4. chore(deps): update dependency semantic-release to v24.2.0 (#870)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    renovate[bot] authored Nov 1, 2024
    Copy the full SHA
    e8463c4 View commit details
  5. chore(deps): update dependency @types/node to v22 (#871)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    renovate[bot] authored Nov 1, 2024
    Copy the full SHA
    d2d8823 View commit details
  6. chore(deps): update dependency ip-address to v10 (#872)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    renovate[bot] authored Nov 1, 2024
    Copy the full SHA
    0e81d42 View commit details

Commits on Nov 27, 2024

  1. fix: Allow to open database files >2GiB and optimize memory consumpti…

    …on for reading files (#878)
    
    * Update index.ts
    
    * Update fs.ts
    
    * New contributor
    
    * Fix ts
    
    * allow to publish again while master branch is updated
    
    * Update package.json
    
    * Update index.ts
    
    * Update tests
    MarianoFacundoArch authored Nov 27, 2024
    Copy the full SHA
    165a304 View commit details
Showing with 37 additions and 13 deletions.
  1. +8 −7 package.json
  2. +1 −0 src/fs.ts
  3. +4 −4 src/index.test.ts
  4. +24 −2 src/index.ts
15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -23,26 +23,27 @@
"Thomas Birke @quafzi <quafzi@netextreme.de>",
"Afzaal Ameer @afzaalace",
"Andrew N Golovkov @AndorCS",
"Gregory Oschwald @oschwald"
"Gregory Oschwald @oschwald",
"Mariano Facundo Scigliano @MarianoFacundoArch"
],
"dependencies": {
"mmdb-lib": "2.1.1",
"tiny-lru": "11.2.11"
},
"devDependencies": {
"@types/ip6addr": "0.2.6",
"@types/jest": "29.5.13",
"@types/jest": "29.5.14",
"@types/netmask": "2.0.5",
"@types/node": "20.16.10",
"@types/node": "22.8.6",
"@types/sinon": "17.0.3",
"ip-address": "9.0.5",
"ip-address": "10.0.1",
"ip6addr": "0.2.5",
"jest": "29.7.0",
"prettier": "3.3.3",
"semantic-release": "24.1.0",
"sinon": "18.0.0",
"semantic-release": "24.2.0",
"sinon": "19.0.2",
"ts-jest": "29.2.5",
"typescript": "5.5.4"
"typescript": "5.6.3"
},
"repository": {
"type": "git",
1 change: 1 addition & 0 deletions src/fs.ts
Original file line number Diff line number Diff line change
@@ -5,4 +5,5 @@ export default {
existsSync: fs.existsSync,
readFile: util.promisify(fs.readFile),
watchFile: fs.watchFile,
createReadStream: fs.createReadStream,
};
8 changes: 4 additions & 4 deletions src/index.test.ts
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ describe('index', () => {
sandbox.stub(fs, 'watchFile').callsFake((paramA, paramB, cb) => {
watchHandler = cb;
});
sandbox.spy(fs, 'readFile');
sandbox.spy(fs, 'createReadStream');
});
afterEach(() => {
sandbox.restore();
@@ -51,17 +51,17 @@ describe('index', () => {
const lookup = await maxmind.open(dbPath, options);
assert(lookup.get('2001:230::'));
assert((fs.watchFile as SinonSpy).calledOnce);
assert((fs.readFile as SinonSpy).calledOnce);
assert((fs.createReadStream as SinonSpy).calledOnce);
});

it('should work with auto updates', async () => {
const options = { watchForUpdates: true };
const lookup = await maxmind.open(dbPath, options);
assert(lookup.get('2001:230::'));
assert((fs.watchFile as SinonSpy).calledOnce);
assert((fs.readFile as SinonSpy).calledOnce);
assert((fs.createReadStream as SinonSpy).calledOnce);
await watchHandler();
assert((fs.readFile as SinonSpy).calledTwice);
assert((fs.createReadStream as SinonSpy).calledTwice);
});

it('should work with auto updates and call specified hook', async () => {
26 changes: 24 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -17,14 +17,36 @@ export interface OpenOpts {
watchForUpdatesHook?: Callback;
}

const readFile = async (filepath: string): Promise<Buffer> => {
return new Promise((resolve, reject) => {
const chunks: Buffer[] = [];
const stream = fs.createReadStream(filepath, {
highWaterMark: 64 * 1024 * 1024, // 64 MB chunks
});

stream.on('data', (chunk: Buffer) => {
chunks.push(chunk);
});

stream.on('end', () => {
resolve(Buffer.concat(chunks));
});

stream.on('error', (err) => {
reject(err);
});
});
};


export const open = async <T extends Response>(
filepath: string,
opts?: OpenOpts,
cb?: Callback
): Promise<Reader<T>> => {
assert(!cb, utils.legacyErrorMessage);

const database = await fs.readFile(filepath);
const database = await readFile(filepath);

if (isGzip(database)) {
throw new Error(
@@ -63,7 +85,7 @@ export const open = async <T extends Response>(
if (!(await waitExists())) {
return;
}
const updatedDatabase = await fs.readFile(filepath);
const updatedDatabase = await readFile(filepath);
cache.clear();
reader.load(updatedDatabase);
if (opts.watchForUpdatesHook) {