/*
* call-seq:
* PGconn.unescape_bytea( string )
*
* Converts an escaped string representation of binary data into binary data --- the
* reverse of #escape_bytea. This is needed when retrieving +bytea+ data in text format,
* but not when retrieving it in binary format.
*
*/
static VALUE
pgconn_s_unescape_bytea(VALUE self, VALUE str)
{
unsigned char *from, *to;
size_t to_len;
VALUE ret;
Check_Type(str, T_STRING);
from = (unsigned char*)StringValuePtr(str);
to = PQunescapeBytea(from, &to_len);
ret = rb_str_new((char*)to, to_len);
OBJ_INFECT(ret, str);
PQfreemem(to);
return ret;
}