#ifndef NODE_BUFFER_H_ #define NODE_BUFFER_H_ #include #include #include #include namespace node { /* A buffer is a chunk of memory stored outside the V8 heap, mirrored by an * object in javascript. The object is not totally opaque, one can access * individual bytes with [] and slice it into substrings or sub-buffers * without copying memory. * * // return an ascii encoded string - no memory is copied * buffer.asciiSlice(0, 3) */ class Buffer : public ObjectWrap { public: ~Buffer(); static void Initialize(v8::Handle target); static Buffer* New(size_t length); // public constructor static Buffer* New(char *data, size_t len); // public constructor static bool HasInstance(v8::Handle val); static char* Data(v8::Handle); static size_t Length(v8::Handle); char* data() { assert(0 && "v0.3 API change: Use node::Buffer::Data()."); return NULL; } size_t length() const { assert(0 && "v0.3 API change: Use node::Buffer::Length()."); return 0; } private: static v8::Persistent constructor_template; static v8::Handle New(const v8::Arguments &args); static v8::Handle BinarySlice(const v8::Arguments &args); static v8::Handle AsciiSlice(const v8::Arguments &args); static v8::Handle Base64Slice(const v8::Arguments &args); static v8::Handle Utf8Slice(const v8::Arguments &args); static v8::Handle BinaryWrite(const v8::Arguments &args); static v8::Handle Base64Write(const v8::Arguments &args); static v8::Handle AsciiWrite(const v8::Arguments &args); static v8::Handle Utf8Write(const v8::Arguments &args); static v8::Handle ByteLength(const v8::Arguments &args); static v8::Handle MakeFastBuffer(const v8::Arguments &args); static v8::Handle Copy(const v8::Arguments &args); Buffer(size_t length); size_t length_; char* data_; }; } // namespace node buffer #endif // NODE_BUFFER_H_