| 229 | } |
| 230 | |
| 231 | Napi::Value Finish(const Napi::CallbackInfo& info) { |
| 232 | Napi::Env env = info.Env(); |
| 233 | if (info.Length() >= 1 && !info[0].IsBuffer() && !info[0].IsString()) { |
| 234 | Napi::TypeError::New(env, "Wrong arguments").ThrowAsJavaScriptException(); |
| 235 | return env.Undefined(); |
| 236 | } |
| 237 | |
| 238 | try { |
| 239 | if (info.Length() >= 1 && info[0].IsBuffer()) { |
| 240 | Napi::Buffer<char> input = info[0].As<Napi::Buffer<char>>(); |
| 241 | return Napi::String::New( |
| 242 | env, stream_->Finish({input.Data(), input.Length()})); |
| 243 | } |
| 244 | if (info.Length() >= 1) { |
| 245 | const std::string input = ToUtf8String(info[0]); |
| 246 | return Napi::String::New(env, stream_->Finish(input)); |
| 247 | } |
| 248 | return Napi::String::New(env, stream_->Finish()); |
| 249 | } catch (opencc::Exception& e) { |
| 250 | Napi::Error::New(env, e.what()).ThrowAsJavaScriptException(); |
| 251 | return env.Undefined(); |
| 252 | } |
| 253 | } |
| 254 | |
| 255 | static Napi::Object Init(Napi::Env env, Napi::Object exports) { |
| 256 | Napi::Function cons = DefineClass( |
nothing calls this directly
no test coverage detected