-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NAPI: use a C-like API for our File class.
Not as nice as wrapping our File class, but at least it works...
- Loading branch information
Showing
5 changed files
with
34 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,23 @@ | ||
#include "file.h" | ||
|
||
void File::init(Napi::Env pEnv, Napi::Object pExports) | ||
{ | ||
auto func = DefineClass(pEnv, "File", {InstanceMethod("contents", &File::contents)}); | ||
#include <libopencor> | ||
|
||
pExports.Set("File", func); | ||
} | ||
static std::vector<libOpenCOR::FilePtr> files; | ||
|
||
File::File(const Napi::CallbackInfo &pInfo) | ||
: Napi::ObjectWrap<File>(pInfo) | ||
napi_value fileContents(const Napi::CallbackInfo &pInfo) | ||
{ | ||
mFile = libOpenCOR::File::create(pInfo[0].ToString().Utf8Value()); | ||
auto fileManager = libOpenCOR::FileManager::instance(); | ||
auto file = fileManager.file(pInfo[0].ToString().Utf8Value()); | ||
auto res = file->contents(); | ||
|
||
return Napi::Buffer<unsigned char>::Copy(pInfo.Env(), res.data(), res.size()); | ||
} | ||
|
||
Napi::Value File::contents(const Napi::CallbackInfo &pInfo) | ||
void fileCreate(const Napi::CallbackInfo &pInfo) | ||
{ | ||
auto res = mFile->contents(); | ||
auto file = libOpenCOR::File::create(pInfo[0].ToString().Utf8Value()); | ||
|
||
return Napi::Buffer<unsigned char>::Copy(pInfo.Env(), res.data(), res.size()); | ||
// Keep track of the file so that it doesn't get garbage collected. | ||
|
||
files.push_back(file); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters