@fayzanx/mmap-io 1.6.12 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -10
- package/mmap-io.js +1 -1
- package/package.json +2 -2
- package/dist/test.js +0 -153
package/README.md
CHANGED
@@ -4,6 +4,10 @@
|
|
4
4
|
## Note
|
5
5
|
- This is a fork of [ARyaskov/mmap-io](https://github.com/ARyaskov/mmap-io) -> [ozra/mmap-io](https://github.com/ozra/mmap-io) and [ipinfo/mmap-utils](https://github.com/ipinfo/mmap-utils)
|
6
6
|
|
7
|
+
This fork fixes a couple of things
|
8
|
+
- Ability to be used with >= Node v22
|
9
|
+
- Ability to handle large files being loaded into the map
|
10
|
+
|
7
11
|
## Quick info
|
8
12
|
|
9
13
|
- Long story short: with this addon you can increase performance of your file interactions by memory mapping files,
|
@@ -32,19 +36,10 @@ Otherwise it requires a C++17 compiler and Python 3.12+ on your machine to build
|
|
32
36
|
|
33
37
|
```
|
34
38
|
|
35
|
-
|
36
|
-
# Fork Notice
|
37
|
-
|
38
|
-
This is a fork of mmap-io (https://github.com/Widdershin/mmap-io/), as the upstream repo is no longer maintained and it didn't compile well on my machine for newer Node.js.
|
39
|
-
|
40
|
-
This version of mmap-io builds on Node up to 22, and provides binaries for Windows and macOS via @mapbox/node-pre-gyp.
|
41
|
-
|
42
39
|
# Author's notice:
|
43
40
|
## Mmap for Node.js
|
44
|
-
mmap(2) / madvise(2) / msync(2) / mincore(2)
|
41
|
+
Please refer for man pages for mmap(2) / madvise(2) / msync(2) / mincore(2).
|
45
42
|
|
46
|
-
**NOTE**: this is a fork of https://github.com/ozra/mmap-io as that repo is
|
47
|
-
unmaintained.
|
48
43
|
|
49
44
|
# Installation
|
50
45
|
|
package/mmap-io.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
module.exports = require("./dist/mmap-
|
1
|
+
module.exports = require("./dist/mmap-io")
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@fayzanx/mmap-io",
|
3
|
-
"version": "1.
|
3
|
+
"version": "1.7.0",
|
4
4
|
"license": "MIT",
|
5
5
|
"author": {
|
6
6
|
"name": "Fayzan Ahmad",
|
@@ -17,7 +17,7 @@
|
|
17
17
|
"binary": {
|
18
18
|
"module_name": "mmap_io",
|
19
19
|
"module_path": "./build/binding/{configuration}/{node_abi}-{platform}-{arch}/",
|
20
|
-
"remote_path": "
|
20
|
+
"remote_path": "v{version}",
|
21
21
|
"package_name": "{module_name}-v{version}-{node_abi}-{platform}-{arch}.tar.gz",
|
22
22
|
"host": "https://github.com/fayzanx/mmap-io/releases/download/"
|
23
23
|
},
|
package/dist/test.js
DELETED
@@ -1,153 +0,0 @@
|
|
1
|
-
// Generated by LiveScript 1.6.0
|
2
|
-
var fs, os, mmap, assert, constants, say, PAGESIZE, PROT_READ, PROT_WRITE, MAP_SHARED, e, fd, size, buffer, out, i$, ix, incore_stats, WRONG_PAGE_SIZE, testFile, testSize, fdW, wBuffer, fdR, rBuffer, i, val;
|
3
|
-
fs = require("fs");
|
4
|
-
os = require("os");
|
5
|
-
mmap = require("../");
|
6
|
-
assert = require("assert");
|
7
|
-
constants = require("constants");
|
8
|
-
say = function(){
|
9
|
-
var args, res$, i$, to$;
|
10
|
-
res$ = [];
|
11
|
-
for (i$ = 0, to$ = arguments.length; i$ < to$; ++i$) {
|
12
|
-
res$.push(arguments[i$]);
|
13
|
-
}
|
14
|
-
args = res$;
|
15
|
-
return console.log.apply(console, args);
|
16
|
-
};
|
17
|
-
say("mmap in test is", mmap);
|
18
|
-
PAGESIZE = mmap.PAGESIZE, PROT_READ = mmap.PROT_READ, PROT_WRITE = mmap.PROT_WRITE, MAP_SHARED = mmap.MAP_SHARED;
|
19
|
-
try {
|
20
|
-
say("mmap.PAGESIZE = ", mmap.PAGESIZE, "tries to overwrite it with 47");
|
21
|
-
mmap.PAGESIZE = 47;
|
22
|
-
say("now mmap.PAGESIZE should be the same:", mmap.PAGESIZE, "silently kept");
|
23
|
-
} catch (e$) {
|
24
|
-
e = e$;
|
25
|
-
say("Caught trying to modify the mmap-object. Does this ever happen?", e);
|
26
|
-
}
|
27
|
-
fd = fs.openSync(process.argv[1], 'r');
|
28
|
-
size = fs.fstatSync(fd).size;
|
29
|
-
say("file size", size);
|
30
|
-
buffer = mmap.map(size, PROT_READ, MAP_SHARED, fd, 0, mmap.MADV_SEQUENTIAL);
|
31
|
-
say("buflen 1 = ", buffer.length);
|
32
|
-
assert.equal(buffer.length, size);
|
33
|
-
say("Give advise with 2 args");
|
34
|
-
mmap.advise(buffer, mmap.MADV_NORMAL);
|
35
|
-
say("Give advise with 4 args");
|
36
|
-
mmap.advise(buffer, 0, mmap.PAGESIZE, mmap.MADV_NORMAL);
|
37
|
-
say("\n\nBuffer contents, read byte for byte backwards and see that nothing explodes:\n");
|
38
|
-
try {
|
39
|
-
out = "";
|
40
|
-
for (i$ = size - 1; i$ >= 0; --i$) {
|
41
|
-
ix = i$;
|
42
|
-
out += String.fromCharCode(buffer[ix]);
|
43
|
-
}
|
44
|
-
incore_stats = mmap.incore(buffer);
|
45
|
-
assert.equal(incore_stats[0], 0);
|
46
|
-
assert.equal(incore_stats[1], 2);
|
47
|
-
} catch (e$) {
|
48
|
-
e = e$;
|
49
|
-
if (e.message !== 'mincore() not implemented') {
|
50
|
-
assert(false, "Shit happened while reading from buffer");
|
51
|
-
}
|
52
|
-
}
|
53
|
-
try {
|
54
|
-
say("read out of bounds test");
|
55
|
-
assert.equal(typeof buffer[size + 47], "undefined");
|
56
|
-
} catch (e$) {
|
57
|
-
e = e$;
|
58
|
-
say("deliberate out of bounds, caught exception - does this thing happen?", e.code, 'err-obj = ', e);
|
59
|
-
}
|
60
|
-
buffer = mmap.map(size, PROT_READ, MAP_SHARED, fd, 0);
|
61
|
-
say("buflen test 5-arg map call = ", buffer.length);
|
62
|
-
assert.equal(buffer.length, size);
|
63
|
-
buffer = mmap.map(size, PROT_READ, MAP_SHARED, fd);
|
64
|
-
say("buflen test 4-arg map call = ", buffer.length);
|
65
|
-
assert.equal(buffer.length, size);
|
66
|
-
if (os.type() !== 'Windows_NT') {
|
67
|
-
fd = fs.openSync(process.argv[1], 'r');
|
68
|
-
buffer = mmap.map(size, PROT_READ, MAP_SHARED, fd, PAGESIZE);
|
69
|
-
say("buflen test 3 = ", buffer.length);
|
70
|
-
assert.equal(buffer.length, size);
|
71
|
-
}
|
72
|
-
fd = fs.openSync(process.argv[1], 'r');
|
73
|
-
try {
|
74
|
-
buffer = mmap.map("foo", PROT_READ, MAP_SHARED, fd, 0);
|
75
|
-
} catch (e$) {
|
76
|
-
e = e$;
|
77
|
-
say("Pass faulty arg - caught deliberate exception: " + e.message);
|
78
|
-
}
|
79
|
-
fd = fs.openSync(process.argv[1], 'r');
|
80
|
-
try {
|
81
|
-
buffer = mmap.map(0, PROT_READ, MAP_SHARED, fd, 0);
|
82
|
-
} catch (e$) {
|
83
|
-
e = e$;
|
84
|
-
say("Pass zero size - caught deliberate exception: " + e.message);
|
85
|
-
}
|
86
|
-
WRONG_PAGE_SIZE = PAGESIZE - 1;
|
87
|
-
fd = fs.openSync(process.argv[1], 'r');
|
88
|
-
try {
|
89
|
-
buffer = mmap.map(size, PROT_READ, MAP_SHARED, fd, WRONG_PAGE_SIZE);
|
90
|
-
} catch (e$) {
|
91
|
-
e = e$;
|
92
|
-
say("Pass wrong page-size as offset - caught deliberate exception: " + e.message);
|
93
|
-
}
|
94
|
-
fd = fs.openSync(process.argv[1], 'r');
|
95
|
-
try {
|
96
|
-
buffer = mmap.map(size, PROT_READ, MAP_SHARED, fd);
|
97
|
-
mmap.advise(buffer, "fuck off");
|
98
|
-
} catch (e$) {
|
99
|
-
e = e$;
|
100
|
-
say("Pass faulty arg to advise() - caught deliberate exception: " + e.message);
|
101
|
-
}
|
102
|
-
say("Now for some write/read tests");
|
103
|
-
try {
|
104
|
-
say("Creates file");
|
105
|
-
testFile = "./tmp-mmap-file";
|
106
|
-
testSize = 47474;
|
107
|
-
fs.writeFileSync(testFile, "");
|
108
|
-
fs.truncateSync(testFile, testSize);
|
109
|
-
say("open write buffer");
|
110
|
-
fdW = fs.openSync(testFile, 'r+');
|
111
|
-
say("fd-write = ", fdW);
|
112
|
-
wBuffer = mmap.map(testSize, PROT_WRITE, MAP_SHARED, fdW);
|
113
|
-
fs.closeSync(fdW);
|
114
|
-
mmap.advise(wBuffer, mmap.MADV_SEQUENTIAL);
|
115
|
-
say("open read bufer");
|
116
|
-
fdR = fs.openSync(testFile, 'r');
|
117
|
-
rBuffer = mmap.map(testSize, PROT_READ, MAP_SHARED, fdR);
|
118
|
-
fs.closeSync(fdR);
|
119
|
-
mmap.advise(rBuffer, mmap.MADV_SEQUENTIAL);
|
120
|
-
say("verify write and read");
|
121
|
-
for (i$ = 0; i$ < testSize; ++i$) {
|
122
|
-
i = i$;
|
123
|
-
val = 32 + i % 60;
|
124
|
-
wBuffer[i] = val;
|
125
|
-
assert.equal(rBuffer[i], val);
|
126
|
-
}
|
127
|
-
say("Write/read verification seemed to work out");
|
128
|
-
} catch (e$) {
|
129
|
-
e = e$;
|
130
|
-
say("Something fucked up in the write/read test::", e.message);
|
131
|
-
}
|
132
|
-
try {
|
133
|
-
say("sync() tests x 4");
|
134
|
-
say("1. Does explicit blocking sync to disk");
|
135
|
-
mmap.sync(wBuffer, 0, testSize, true, false);
|
136
|
-
say("2. Does explicit blocking sync without offset/length arguments");
|
137
|
-
mmap.sync(wBuffer, true, false);
|
138
|
-
say("3. Does explicit sync to disk without blocking/invalidate flags");
|
139
|
-
mmap.sync(wBuffer, 0, testSize);
|
140
|
-
say("4. Does explicit sync with no additional arguments");
|
141
|
-
mmap.sync(wBuffer);
|
142
|
-
} catch (e$) {
|
143
|
-
e = e$;
|
144
|
-
say("Something fucked up for syncs::", e.message);
|
145
|
-
}
|
146
|
-
try {
|
147
|
-
fs.unlinkSync(testFile);
|
148
|
-
} catch (e$) {
|
149
|
-
e = e$;
|
150
|
-
say("Failed to remove test-file", testFile);
|
151
|
-
}
|
152
|
-
say("\nAll done");
|
153
|
-
process.exit(0);
|