New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

cursor

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cursor

Cursor implementation for node buffers

  • 0.1.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

Build Status

Description

Wrap your buffers! Fluid API! Other things!

Usage

return Cursor.create(2)
	.writeInt8(10)
	.writeUInt32BE(10)
	.buffer();

##Construction

//both work
var a = new Cursor(buffer);
var b = Cursor(buffer);

//also accepts Buffer constructor arguments
var c = Cursor(10); //size
var d = Cursor([0x01, 0x02]); // octals

###Cloning

//create a cursor pointing at the same buffer
//and the same index
var pos = curs.tell();
var cl = curs.clone();
pos == cl.tell(); //true

//create a cursor and immediately seek to a new pos
var pos = curs.rewind().tell();
var cl = curs.clone(100);
cl.tell() == pos; //false

##Reading

Cursor implements all of the Buffer.readXXX methods in addition to toString.

##Writing

Cursor implements all of the Buffer.writeXXX methods in addition to write and fill.

However, Cursor deviates from Buffer by not offering a copy method. Instead, use copyFrom

//bytes from c2 are copied into c1
c1.copyFrom(c2);

##Extending Sometimes it's beneficial to write have your own read/write primitives, while still providing access to the standard r/w operations. In those cases, extending Cursor can help.

var ProtocolCursor = Cursor.extend(
{
	readInt: function()
	{
		return this.readInt32BE();
	},
	
	writeInt: function(n)
	{
		return this.writeInt32BE(n);
	},
	
	readCrazyObject: function()
	{
		var len = this.readInt();
		var bytes = this.slice(len);
		
		//unpack your bytes
		...
	}
});

var obj = ProtocolCursor(buffer).readCrazyObject();

License (MIT)

Copyright (c) 2013 Dimerica Industries, LLC

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
    
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
    
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Keywords

FAQs

Package last updated on 04 Feb 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc