Skip to content

Commit

Permalink
Adding optional encoding flag to base64.decode().
Browse files Browse the repository at this point in the history
  • Loading branch information
brianloveswords committed Mar 16, 2011
1 parent 1fd832b commit a6c6a5a
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions base64.cc
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,9 @@ Handle<Value>
base64_decode_binding(const Arguments &args)
{
HandleScope scope;
node::encoding encflag = BINARY;

if (args.Length() != 1)
if (args.Length() < 1)
return VException("One argument required - buffer or string with data to decode");

int outlen;
Expand All @@ -172,7 +173,13 @@ base64_decode_binding(const Arguments &args)
decoded = base64_decode(*b64data, b64data.length(), &outlen);
}

Local<Value> ret = Encode(decoded, outlen, BINARY);
if (args.Length() > 1 && args[1]->IsString()) {
String::AsciiValue flag(args[1]->ToString());
if (strcmp("utf8", *flag) == 0) encflag = UTF8;
}

Local<Value> ret = Encode(decoded, outlen, encflag);

delete [] decoded;
return scope.Close(ret);
}
Expand Down

0 comments on commit a6c6a5a

Please sign in to comment.