package.json
8.6 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
{
"_args": [
[
{
"raw": "ref@>= 0.1.3",
"scope": null,
"escapedName": "ref",
"name": "ref",
"rawSpec": ">= 0.1.3",
"spec": ">=0.1.3",
"type": "range"
},
"/Users/fzy/project/koa2_Sequelize_project/node_modules/win32api"
]
],
"_from": "ref@>=0.1.3",
"_id": "ref@1.3.5",
"_inCache": true,
"_location": "/ref",
"_nodeVersion": "8.2.1",
"_npmOperationalInternal": {
"host": "s3://npm-registry-packages",
"tmp": "tmp/ref-1.3.5.tgz_1504024578003_0.675216818228364"
},
"_npmUser": {
"name": "tootallnate",
"email": "nathan@tootallnate.net"
},
"_npmVersion": "5.3.0",
"_phantomChildren": {},
"_requested": {
"raw": "ref@>= 0.1.3",
"scope": null,
"escapedName": "ref",
"name": "ref",
"rawSpec": ">= 0.1.3",
"spec": ">=0.1.3",
"type": "range"
},
"_requiredBy": [
"/ffi",
"/ref-struct",
"/win32api",
"/win32ole"
],
"_resolved": "https://registry.npmjs.org/ref/-/ref-1.3.5.tgz",
"_shasum": "0e33f080cdb94a3d95312b2b3b1fd0f82044ca0f",
"_shrinkwrap": null,
"_spec": "ref@>= 0.1.3",
"_where": "/Users/fzy/project/koa2_Sequelize_project/node_modules/win32api",
"author": {
"name": "Nathan Rajlich",
"email": "nathan@tootallnate.net",
"url": "http://tootallnate.net"
},
"bugs": {
"url": "https://github.com/TooTallNate/ref/issues"
},
"dependencies": {
"bindings": "1",
"debug": "2",
"nan": "2"
},
"description": "Turn Buffer instances into \"pointers\"",
"devDependencies": {
"dox": "0.4.4",
"highlight.js": "1",
"jade": "^0.35.0",
"marked": "^0.3.2",
"mocha": "*",
"weak": "1"
},
"directories": {},
"dist": {
"integrity": "sha512-2cBCniTtxcGUjDpvFfVpw323a83/0RLSGJJY5l5lcomZWhYpU2cuLdsvYqMixvsdLJ9+sTdzEkju8J8ZHDM2nA==",
"shasum": "0e33f080cdb94a3d95312b2b3b1fd0f82044ca0f",
"tarball": "https://registry.npmjs.org/ref/-/ref-1.3.5.tgz"
},
"gitHead": "c6211d08807596dda5a49f7bc5ed14d2ee6463ad",
"gypfile": true,
"homepage": "https://github.com/TooTallNate/ref#readme",
"keywords": [
"native",
"buffer",
"extensions",
"c++",
"pointer",
"reference",
"dereference",
"type",
"int",
"long",
"float",
"double",
"byte",
"64"
],
"license": "MIT",
"main": "./lib/ref.js",
"maintainers": [
{
"name": "tootallnate",
"email": "nathan@tootallnate.net"
}
],
"name": "ref",
"optionalDependencies": {},
"readme": "ref\n===\n### Turn Buffer instances into \"pointers\"\n[](https://travis-ci.org/TooTallNate/ref)\n[](https://ci.appveyor.com/project/TooTallNate/ref)\n\n\nThis module is inspired by the old `Pointer` class from node-ffi, but with the\nintent of using Node's fast `Buffer` instances instead of a slow C++ `Pointer`\nclass. These two concepts were previously very similar, but now this module\nbrings over the functionality that Pointers had and Buffers are missing, so\nnow Buffers are a lot more powerful.\n\n### Features:\n\n * Get the memory address of any `Buffer` instance\n * Read/write references to JavaScript Objects into `Buffer` instances\n * Read/write `Buffer` instances' memory addresses to other `Buffer` instances\n * Read/write `int64_t` and `uint64_t` data values (Numbers or Strings)\n * A \"type\" convention, so that you can specify a buffer as an `int *`,\n and reference/dereference at will.\n * Offers a buffer instance representing the `NULL` pointer\n\n\nInstallation\n------------\n\nInstall with `npm`:\n\n``` bash\n$ npm install ref\n```\n\n\nExamples\n--------\n\n#### referencing and derefencing\n\n``` js\nvar ref = require('ref')\n\n// so we can all agree that a buffer with the int value written\n// to it could be represented as an \"int *\"\nvar buf = new Buffer(4)\nbuf.writeInt32LE(12345, 0)\n\n// first, what is the memory address of the buffer?\nconsole.log(buf.address()) // ← 140362165284824\n\n// using `ref`, you can set the \"type\", and gain magic abilities!\nbuf.type = ref.types.int\n\n// now we can dereference to get the \"meaningful\" value\nconsole.log(buf.deref()) // ← 12345\n\n\n// you can also get references to the original buffer if you need it.\n// this buffer could be thought of as an \"int **\"\nvar one = buf.ref()\n\n// and you can dereference all the way back down to an int\nconsole.log(one.deref().deref()) // ← 12345\n```\n\nSee the [full API Docs][docs] for more examples.\n\n\nThe \"type\" interface\n--------------------\n\nYou can easily define your own \"type\" objects at attach to `Buffer` instances.\nIt just needs to be a regular JavaScript Object that contains the following\nproperties:\n\n| **Name** | **Data Type** | **Description**\n|:--------------|:---------------------------------|:----------------------------------\n| `size` | Number | The size in bytes required to hold this type.\n| `indirection` | Number | The current level of indirection of the buffer. Usually this would be _1_, and gets incremented on Buffers from `ref()` calls. A value of less than or equal to _0_ is invalid.\n| `get` | Function (buffer, offset) | The function to invoke when dereferencing this type when the indirection level is _1_.\n| `set` | Function (buffer, offset, value) | The function to invoke when setting a value to a buffer instance.\n| `name` | String | _(optional)_ The name to use during debugging for this type.\n| `alignment` | Number | _(optional)_ The alignment of this type when placed in a struct. Defaults to the type's `size`.\n\nBe sure to check out the Wiki page of [\"Known\nTypes\"](https://github.com/TooTallNate/ref/wiki/Known-%22types%22), for the list\nof built-in ref types, as well as known external type implementations.\n\nFor example, you could define a \"bigint\" type that dereferences into a\n[`bigint`](https://github.com/substack/node-bigint) instance:\n\n``` js\nvar ref = require('ref')\nvar bigint = require('bigint')\n\n// define the \"type\" instance according to the spec\nvar BigintType = {\n size: ref.sizeof.int64\n , indirection: 1\n , get: function (buffer, offset) {\n // return a bigint instance from the buffer\n return bigint.fromBuffer(buffer)\n }\n , set: function (buffer, offset, value) {\n // 'value' would be a bigint instance\n var val = value.toString()\n return ref.writeInt64(buffer, offset || 0, val)\n }\n}\n\n// now we can create instances of the type from existing buffers.\n// \"buf\" is some Buffer instance returned from some external data\n// source, which should contain \"bigint\" binary data.\nbuf.type = BigintType\n\n// and now you can create \"bigint\" instances using this generic \"types\" API\nvar val = buf.deref()\n .add('1234')\n .sqrt()\n .shiftLeft(5)\n```\n\nBuild the docs\n--------------\n\nInstall the dev dependencies:\n\n``` bash\n$ npm install\n```\n\nGenerate the docs:\n\n``` bash\n$ npm run docs\n```\n\n\nLicense\n-------\n\n(The MIT License)\n\nCopyright (c) 2012 Nathan Rajlich <nathan@tootallnate.net>\n\nPermission is hereby granted, free of charge, to any person obtaining\na copy of this software and associated documentation files (the\n'Software'), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\nIN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\nCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\nTORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\nSOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n[docs]: http://tootallnate.github.com/ref\n",
"readmeFilename": "README.md",
"repository": {
"type": "git",
"url": "git://github.com/TooTallNate/ref.git"
},
"scripts": {
"docs": "node docs/compile",
"install": "node-gyp rebuild",
"test": "mocha -gc --reporter spec --use_strict"
},
"version": "1.3.5"
}