node-jpickle
Full-javascript parser for Python's pickle format.
It currently supports most opcodes for:
- protocol 0
- protocol 1
- protocol 2
Installation
npm install jpickle
Usage
Here is a basic example for parsing a pickled string:
var jpickle = ;jpickle;
To handle more complex objects from jpickle the Javascript objects first need to be registered with the the module. For most basic cases these can just be empty objects that are mapped to a a python class name. If the type is not registered with the emulated member then the unpickle will fail with an exception.
Python
self.data = "test"
Node
{} var jpickle = ;jpickleemulated'__main__.MyClass' = MyClass;var unpickled = jpickle;// unpickled.data is now "test"
If the class being unpickled uses inheritance the base classes need to be registered also.
Python
self.data = "test" self.myclass = self.myclasses = .data = "new test value" self.subvalue = 12
Node
{} {} {} var jpickle = ;jpickleemulated'__main__.MyClass' = MyClass;jpickleemulated'__main__.MyOtherClass' = MyOtherClass;jpickleemulated'__main__.MySubClass' = MySubClass; var unpickled = jpickle;// unpickled.myclasses[0].data is now "new test value"// unpickled.subvalue is now "12"
In cases that more emulation is desired such as member functions those can be added to the object prototype.
Running Tests
To run the tests, install Mocha then run:
mocha