Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

initial iolayer changes, put aside

  • Loading branch information...
commit d76505540a5e15db940b370210f9ef2a0332c48b 1 parent 5674939
Tony Cook authored
Showing with 68 additions and 0 deletions.
  1. +63 −0 Imager.xs
  2. +5 −0 t/t07iolayer.t
63 Imager.xs
View
@@ -1107,6 +1107,69 @@ void
io_glue_DESTROY(ig)
Imager::IO ig
+long
+seek(ig, offset, whence)
+ Imager::IO ig
+ long offset
+ int whence
+ CODE:
+ RETVAL = ig->seekcb(ig, offset, whence);
+ OUTPUT:
+ RETVAL
+
+SV *
+read(ig, sv, len)
+ Imager::IO ig
+ SV *sv
+ int len
+ CODE:
+ if (len <= 0) {
+ RETVAL = &PL_sv_undef;
+ }
+ else {
+ char *buf = SvGROW(sv, len+1);
+ int result_len = ig->readcb(ig, buf, len);
+ if (result_len >= 0) {
+ RETVAL = newSViv(result_len);
+ SvCUR_set(sv, result_len);
+ *SvEND(sv) = '\0';
+ SvUTF8_off(sv); /* _always_ octets */
+ SvSETMAGIC(sv);
+ }
+ else {
+ RETVAL = &PL_sv_undef;
+ }
+ }
+ OUTPUT:
+ RETVAL
+
+SV *
+write(ig, data_sv)
+ Imager::IO ig
+ SV *data_sv
+ PREINIT:
+ STRLEN len;
+ void const *buf;
+ int result;
+ CODE:
+#ifdef SvUTF8
+ if (SvUTF8(data_sv)) {
+ /* make a copy and downgrade it, so we get octets.
+ croaks() if we can't downgrade */
+ data_sv = sv_2mortal(newSVsv(data_sv));
+ sv_utf8_downgrade(data_sv, FALSE);
+ }
+#endif
+ buf = SvPV(data_sv, len);
+ result = ig->writecb(ig, buf, len);
+ if (result <= 0) {
+ RETVAL = &PL_sv_undef;
+ }
+ else {
+ RETVAL = newSViv(result);
+ }
+ OUTPUT:
+ RETVAL
MODULE = Imager PACKAGE = Imager
5 t/t07iolayer.t
View
@@ -117,3 +117,8 @@ $work = '';
ok(Imager::i_writeppm_wiol($im, $IO9), "write to short cb");
ok($work eq $data2, "short write image match");
+{ # test the new methods
+ my $io = Imager::io_new_bufchain();
+ ok($io, "make bufchain");
+ is($io->write("test"), 4, "write");
+}
Please sign in to comment.
Something went wrong with that request. Please try again.