GT2/GT2-iOS/node_modules/smart-buffer/package.json

107 lines
13 KiB
JSON

{
"_args": [
[
{
"raw": "smart-buffer@^1.0.13",
"scope": null,
"escapedName": "smart-buffer",
"name": "smart-buffer",
"rawSpec": "^1.0.13",
"spec": ">=1.0.13 <2.0.0",
"type": "range"
},
"/Volumes/2009-SSD/GT2/GT2-iOS/node_modules/socks"
]
],
"_from": "smart-buffer@>=1.0.13 <2.0.0",
"_id": "smart-buffer@1.1.15",
"_inCache": true,
"_location": "/smart-buffer",
"_nodeVersion": "6.1.0",
"_npmOperationalInternal": {
"host": "packages-18-east.internal.npmjs.com",
"tmp": "tmp/smart-buffer-1.1.15.tgz_1485802535898_0.37321774289011955"
},
"_npmUser": {
"name": "joshglazebrook",
"email": "npm@joshglazebrook.com"
},
"_npmVersion": "3.8.6",
"_phantomChildren": {},
"_requested": {
"raw": "smart-buffer@^1.0.13",
"scope": null,
"escapedName": "smart-buffer",
"name": "smart-buffer",
"rawSpec": "^1.0.13",
"spec": ">=1.0.13 <2.0.0",
"type": "range"
},
"_requiredBy": [
"/socks"
],
"_resolved": "https://registry.npmjs.org/smart-buffer/-/smart-buffer-1.1.15.tgz",
"_shasum": "7f114b5b65fab3e2a35aa775bb12f0d1c649bf16",
"_shrinkwrap": null,
"_spec": "smart-buffer@^1.0.13",
"_where": "/Volumes/2009-SSD/GT2/GT2-iOS/node_modules/socks",
"author": {
"name": "Josh Glazebrook"
},
"bugs": {
"url": "https://github.com/JoshGlazebrook/smart-buffer/issues"
},
"dependencies": {},
"description": "A smarter Buffer that keeps track of its own read and write positions while growing endlessly.",
"devDependencies": {
"chai": "^3.5.0",
"coveralls": "^2.11.15",
"istanbul": "^0.4.3",
"mocha": "^3.2.0",
"mocha-lcov-reporter": "^1.2.0"
},
"directories": {},
"dist": {
"shasum": "7f114b5b65fab3e2a35aa775bb12f0d1c649bf16",
"tarball": "https://registry.npmjs.org/smart-buffer/-/smart-buffer-1.1.15.tgz"
},
"engines": {
"node": ">= 0.10.15",
"npm": ">= 1.3.5"
},
"gitHead": "071f618b339a341c2617ac41ea2a77132fd307e8",
"homepage": "https://github.com/JoshGlazebrook/smart-buffer/",
"keywords": [
"buffer",
"smart",
"serialize",
"packet",
"network",
"cursor",
"simple"
],
"license": "MIT",
"main": "lib/smart-buffer.js",
"maintainers": [
{
"name": "joshglazebrook",
"email": "josh@joshglazebrook.com"
}
],
"name": "smart-buffer",
"optionalDependencies": {},
"readme": "smart-buffer [![Build Status](https://travis-ci.org/JoshGlazebrook/smart-buffer.svg?branch=master)](https://travis-ci.org/JoshGlazebrook/smart-buffer) [![Coverage Status](https://coveralls.io/repos/github/JoshGlazebrook/smart-buffer/badge.svg?branch=master)](https://coveralls.io/github/JoshGlazebrook/smart-buffer?branch=master)\n=============\n\nsmart-buffer is a light Buffer wrapper that takes away the need to keep track of what position to read and write data to and from the underlying Buffer. It also adds null terminating string operations and **grows** as you add more data.\n\n\n### What it's useful for:\n\nI created smart-buffer because I wanted to simplify the process of using Buffer for building and reading network packets to send over a socket. Rather than having to keep track of which position I need to write a UInt16 to after adding a string of variable length, I simply don't have to.\n\nKey Features:\n* Proxies all of the Buffer write and read functions.\n* Keeps track of read and write positions for you.\n* Grows the internal Buffer as you add data to it. \n* Useful string operations. (Null terminating strings)\n* Allows for inserting values at specific points in the internal Buffer.\n\n#### Note:\nsmart-buffer can be used for writing to an underlying buffer as well as reading from it. It however does not function correctly if you're mixing both read and write operations with each other.\n\n## Installing:\n\n`npm install smart-buffer`\n\n## Using smart-buffer\n\n### Example\n\nSay you were building a packet that had to conform to the following protocol:\n\n`[PacketType:2][PacketLength:2][Data:XX]`\n\nTo build this packet using the vanilla Buffer class, you would have to count up the length of the data payload beforehand. You would also need to keep track of the current \"cursor\" position in your Buffer so you write everything in the right places. With smart-buffer you don't have to do either of those things.\n\n```javascript\nfunction createLoginPacket(username, password, age, country) {\n var packet = new SmartBuffer();\n packet.writeUInt16LE(0x0060); // Login Packet Type/ID\n packet.writeStringNT(username);\n packet.writeStringNT(password);\n packet.writeUInt8(age);\n packet.writeStringNT(country);\n packet.writeUInt16LE(packet.length - 2, 2);\n \n return packet.toBuffer();\n}\n```\nWith the above function, you now can do this:\n```javascript\nvar login = createLoginPacket(\"Josh\", \"secret123\", 22, \"United States\");\n\n// <Buffer 60 00 1e 00 4a 6f 73 68 00 73 65 63 72 65 74 31 32 33 00 16 55 6e 69 74 65 64 20 53 74 61 74 65 73 00>\n```\nNotice that the `[PacketLength:2]` part of the packet was inserted after we had added everything else, and as shown in the Buffer dump above, is in the correct location along with everything else.\n\nReading back the packet we created above is just as easy:\n```javascript\n\nvar reader = new SmartBuffer(login);\n\nvar logininfo = {\n packetType: reader.readUInt16LE(),\n packetLength: reader.readUInt16LE(),\n username: reader.readStringNT(),\n password: reader.readStringNT(),\n age: reader.readUInt8(),\n country: reader.readStringNT()\n};\n\n/*\n{ \n packetType: 96, (0x0060)\n packetLength: 30,\n username: 'Josh',\n password: 'secret123',\n age: 22,\n country: 'United States' \n};\n*/\n```\n\n# Api Reference:\n\n### Constructing a smart-buffer\n\nsmart-buffer has a few different constructor signatures you can use. By default, utf8 encoding is used, and the internal Buffer length will be 4096. When reading from a Buffer, smart-buffer does NOT make a copy of the Buffer. It reads from the Buffer it was given.\n\n```javascript\nvar SmartBuffer = require('smart-buffer');\n\n// Reading from an existing Buffer:\nvar reader = new SmartBuffer(buffer);\nvar reader = new SmartBuffer(buffer, 'ascii');\n\n// Writing to a new Buffer:\nvar writer = new SmartBuffer(); // Defaults to utf8, 4096 length internal Buffer.\nvar writer = new SmartBuffer(1024); // Defaults to utf8, 1024 length internal Buffer.\nvar writer = new SmartBuffer('ascii'); // Sets to ascii encoding, 4096 length internal buffer.\nvar writer = new SmartBuffer(1024, 'ascii'); // Sets to ascii encoding, 1024 length internal buffer.\n```\n\n## Reading Data\n\nsmart-buffer supports all of the common read functions you will find in the vanilla Buffer class. The only difference is, you do not need to specify which location to start reading from. This is possible because as you read data out of a smart-buffer, it automatically progresses an internal read offset/position to know where to pick up from on the next read.\n\n## Reading Numeric Values\n\nWhen numeric values, you simply need to call the function you want, and the data is returned.\n\nSupported Operations:\n* readInt8\n* readInt16BE\n* readInt16LE\n* readInt32BE\n* readInt32LE\n* readUInt8\n* readUInt16BE\n* readUInt16LE\n* readUInt32BE\n* readUInt32LE\n* readFloatBE\n* readFloatLE\n* readDoubleBE\n* readDoubleLE\n\n```javascript\nvar reader = new SmartBuffer(somebuffer);\nvar num = reader.readInt8();\n```\n\n## Reading String Values\n\nWhen reading String values, you can either choose to read a null terminated string, or a string of a specified length.\n\n### SmartBuffer.readStringNT( [encoding] )\n> `String` **String encoding to use** - Defaults to the encoding set in the constructor, or utf8. \n\nreturns `String`\n\n> Note: When readStringNT is called and there is no null character found, smart-buffer will read to the end of the internal Buffer.\n\n### SmartBuffer.readString( [length], [encoding] )\n### SmartBuffer.readString( [length] )\n### SmartBuffer.readString( [encoding] )\n> `Number` **Length of the string to read**\n\n> `String` **String encoding to use** - Defaults to the encoding set in the constructor, or utf8.\n\nreturns `String`\n\n> Note: When readString is called without a specified length, smart-buffer will read to the end of the internal Buffer.\n\n\n\n## Reading Buffer Values\n\n### SmartBuffer.readBuffer( length )\n> `Number` **Length of data to read into a Buffer**\n\nreturns `Buffer`\n\n> Note: This function uses `slice` to retrieve the Buffer.\n\n\n### SmartBuffer.readBufferNT()\n\nreturns `Buffer`\n\n> Note: This reads the next sequence of bytes in the buffer until a null (0x00) value is found. (Null terminated buffer)\n> Note: This function uses `slice` to retrieve the Buffer.\n\n\n## Writing Data\n\nsmart-buffer supports all of the common write functions you will find in the vanilla Buffer class. The only difference is, you do not need to specify which location to write to in your Buffer by default. You do however have the option of **inserting** a piece of data into your smart-buffer at a given location. \n\n\n## Writing Numeric Values\n\n\nFor numeric values, you simply need to call the function you want, and the data is written at the end of the internal Buffer's current write position. You can specify a offset/position to **insert** the given value at, but keep in mind this does not override data at the given position. This feature also does not work properly when inserting a value beyond the current internal length of the smart-buffer (length being the .length property of the smart-buffer instance you're writing to)\n\nSupported Operations:\n* writeInt8\n* writeInt16BE\n* writeInt16LE\n* writeInt32BE\n* writeInt32LE\n* writeUInt8\n* writeUInt16BE\n* writeUInt16LE\n* writeUInt32BE\n* writeUInt32LE\n* writeFloatBE\n* writeFloatLE\n* writeDoubleBE\n* writeDoubleLE\n\nThe following signature is the same for all the above functions:\n\n### SmartBuffer.writeInt8( value, [offset] )\n> `Number` **A valid Int8 number**\n\n> `Number` **The position to insert this value at** \n\nreturns this \n\n> Note: All write operations return `this` to allow for chaining.\n\n## Writing String Values\n\nWhen reading String values, you can either choose to write a null terminated string, or a non null terminated string.\n\n### SmartBuffer.writeStringNT( value, [offset], [encoding] )\n### SmartBuffer.writeStringNT( value, [offset] )\n### SmartBuffer.writeStringNT( value, [encoding] )\n> `String` **String value to write**\n\n> `Number` **The position to insert this String at**\n\n> `String` **The String encoding to use.** - Defaults to the encoding set in the constructor, or utf8.\n\nreturns this\n\n### SmartBuffer.writeString( value, [offset], [encoding] )\n### SmartBuffer.writeString( value, [offset] )\n### SmartBuffer.writeString( value, [encoding] )\n> `String` **String value to write**\n\n> `Number` **The position to insert this String at**\n\n> `String` **The String encoding to use** - Defaults to the encoding set in the constructor, or utf8.\n\nreturns this\n\n\n## Writing Buffer Values\n\n### SmartBuffer.writeBuffer( value, [offset] )\n> `Buffer` **Buffer value to write**\n\n> `Number` **The position to insert this Buffer's content at**\n\nreturns this\n\n### SmartBuffer.writeBufferNT( value, [offset] )\n> `Buffer` **Buffer value to write**\n\n> `Number` **The position to insert this Buffer's content at**\n\nreturns this\n\n\n## Utility Functions\n\n### SmartBuffer.clear()\nResets the SmartBuffer to its default state where it can be reused for reading or writing.\n\n### SmartBuffer.remaining()\n\nreturns `Number` The amount of data left to read based on the current read Position.\n\n### SmartBuffer.skip( value )\n> `Number` **The amount of bytes to skip ahead**\n\nSkips the read position ahead by the given value.\n\nreturns this\n\n### SmartBuffer.rewind( value )\n> `Number` **The amount of bytes to reward backwards**\n\nRewinds the read position backwards by the given value.\n\nreturns this\n\n### SmartBuffer.skipTo( position )\n> `Number` **The point to skip the read position to**\n\nMoves the read position to the given point.\nreturns this\n\n### SmartBuffer.toBuffer()\n\nreturns `Buffer` A Buffer containing the contents of the internal Buffer.\n\n> Note: This uses the slice function.\n\n### SmartBuffer.toString( [encoding] )\n> `String` **The String encoding to use** - Defaults to the encoding set in the constructor, or utf8.\n\nreturns `String` The internal Buffer in String representation.\n\n### SmartBuffer.destroy()\nAttempts to destroy the smart-buffer.\n\nreturns this\n\n## Properties\n\n### SmartBuffer.length\n\nreturns `Number` **The length of the data that is being tracked in the internal Buffer** - Does NOT return the absolute length of the internal Buffer being written to.\n\n## License\n\nThis work is licensed under the [MIT license](http://en.wikipedia.org/wiki/MIT_License).",
"readmeFilename": "README.md",
"repository": {
"type": "git",
"url": "git+https://github.com/JoshGlazebrook/smart-buffer.git"
},
"scripts": {
"coverage": "istanbul cover node_modules/mocha/bin/_mocha recursive test",
"fullcoverage": "istanbul -include-all-sources cover node_modules/mocha/bin/_mocha recursive test",
"test": "mocha test/smart-buffer.test.js"
},
"typings": "typings/index",
"version": "1.1.15"
}