static Handle<String>
ReadFile (const string& name)
{
+
FILE* file = fopen(name.c_str(), "rb");
if (file == NULL) return Handle<String>();
-
+
fseek(file, 0, SEEK_END);
int size = ftell(file);
rewind(file);
- char* chars = new char[size + 1];
+ char chars[size+1];
chars[size] = '\0';
for (int i = 0; i < size;) {
int read = fread(&chars[i], 1, size - i, file);
+ if(read <= 0) {
+ perror("read()");
+ }
i += read;
}
+
+ uint16_t expanded_base[size+1];
+ expanded_base[size] = '\0';
+ for(int i = 0; i < size; i++)
+ expanded_base[i] = chars[i];
+
fclose(file);
- Handle<String> result = String::New(chars, size);
- delete[] chars;
- return result;
+
+ HandleScope scope;
+ Local<String> result = String::New(expanded_base, size);
+
+ return scope.Close(result);
}
static Handle<Value>
HandleScope scope;
String::Utf8Value filename(args[0]);
-
Handle<String> output = ReadFile (*filename);
return scope.Close(output);
}
} else {
Handle<String> s = data->ToString();
oi_buf *buf = oi_buf_new2(s->Length());
- s->WriteAscii(buf->base, 0, s->Length());
+
+ uint16_t expanded[s->Length()];
+ s->Write(expanded, 0, s->Length());
+
+ for(int i = 0; i < s->Length(); i++) {
+ buf->base[i] = expanded[i];
+ }
+
output.push_back(buf);
}
connection.Write();
if(length) {
// TODO ByteArray?
- Handle<String> chunk = String::New(base, length);
+ //
+
+ uint16_t expanded_base[length];
+ for(int i = 0; i < length; i++) {
+ expanded_base[i] = base[i];
+ }
+
+ Handle<String> chunk = String::New(expanded_base, length);
argv[0] = chunk;
} else {
argv[0] = Null();