-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
78 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,4 @@ results | |
|
||
npm-debug.log | ||
node_modules | ||
build |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"targets": [ | ||
{ | ||
"target_name": "volume", | ||
"sources": [ "src/volume.cc" ] | ||
} | ||
] | ||
} |
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
|
||
#include <CoreFoundation/CFURL.h> | ||
#include <CoreFoundation/CFString.h> | ||
|
||
using namespace v8; | ||
|
||
Local<String> MYCFStringGetV8String(CFStringRef aString) { | ||
|
||
if (aString == NULL) { | ||
return String::New(""); | ||
} | ||
|
||
CFIndex length = CFStringGetLength(aString); | ||
CFIndex maxSize = CFStringGetMaximumSizeForEncoding(length, kCFStringEncodingUTF8); | ||
char *buffer = (char *) malloc(maxSize); | ||
|
||
if (CFStringGetCString(aString, buffer, maxSize, kCFStringEncodingUTF8)) { | ||
|
||
Local<String> result = String::New(buffer); | ||
free(buffer); | ||
|
||
return result; | ||
} | ||
|
||
return String::New(""); | ||
} | ||
|
||
Handle<Value> MethodGetVolumeName(const Arguments& args) { | ||
HandleScope scope; | ||
|
||
String::AsciiValue aPath(args[0]); | ||
|
||
CFStringRef out; | ||
CFErrorRef error; | ||
|
||
CFStringRef volumePath = CFStringCreateWithCString(NULL, *aPath, kCFStringEncodingUTF8); | ||
CFURLRef url = CFURLCreateWithFileSystemPath(NULL, volumePath, kCFURLPOSIXPathStyle, true); | ||
|
||
if(CFURLCopyResourcePropertyForKey(url, kCFURLVolumeNameKey, &out, &error)) { | ||
|
||
Local<String> result = MYCFStringGetV8String(out); | ||
|
||
return scope.Close(result); | ||
} else { | ||
|
||
Local<String> desc = MYCFStringGetV8String(CFErrorCopyDescription(error)); | ||
ThrowException(Exception::Error(desc)->ToObject()); | ||
|
||
return scope.Close(Undefined()); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
|
||
#include <node.h> | ||
#include <v8.h> | ||
|
||
#ifdef __APPLE__ | ||
#include "impl-apple.cc" | ||
#else | ||
#error This platform is not implemented yet | ||
#endif | ||
|
||
void init(v8::Handle<v8::Object> exports) { | ||
exports->Set(v8::String::NewSymbol("getVolumeName"), v8::FunctionTemplate::New(MethodGetVolumeName)->GetFunction()); | ||
} | ||
|
||
NODE_MODULE(volume, init) |