Class: NSData

Inherits:
Object show all
Defined in:
ext/accessibility/bridge/bridge.c,
ext/accessibility/bridge/bridge.c

Overview

A 50% drop-in replacement for Cocoa's NSData class. Almost all non-deprecated methods have been bridged.

See Apple's Developer Reference for documentation on the methods available in this class.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.dataObject

TODO: implement commented out methods



679
680
681
682
683
684
# File 'ext/accessibility/bridge/bridge.c', line 679

static
VALUE
rb_data_data(VALUE self)
{
  return wrap_nsdata([NSData data]);
}

.dataWithContentsOfURL(url) ⇒ Object

rb_define_singleton_method(rb_cData, "dataWithContentsOfFile", rb_data_with_contents_of_file, 1);



686
687
688
689
690
691
692
693
694
# File 'ext/accessibility/bridge/bridge.c', line 686

static
VALUE
rb_data_with_contents_of_url(VALUE self, VALUE url)
{
  NSData* data = [NSData dataWithContentsOfURL:unwrap_nsurl(url)];
  if (data)
    return wrap_nsdata(data);
  return Qnil;
}

Instance Method Details

#isEqualToData(other) ⇒ Object Also known as: ==

rb_define_method(rb_cData, "subdataWithRange", rb_data_subrange, 1);



703
704
705
706
707
708
# File 'ext/accessibility/bridge/bridge.c', line 703

static
VALUE
rb_data_equality(VALUE self, VALUE other)
{
  OBJC_EQUALITY(rb_cData, unwrap_nsdata);
}

#lengthObject



696
697
698
699
700
701
# File 'ext/accessibility/bridge/bridge.c', line 696

static
VALUE
rb_data_length(VALUE self)
{
  return ULONG2NUM([unwrap_nsdata(self) length]);
}

#to_strObject

rb_define_method(rb_cData, "writeToURL", rb_data_write_to_url, -1);



731
732
733
734
735
736
737
738
739
# File 'ext/accessibility/bridge/bridge.c', line 731

static
VALUE
rb_data_to_str(VALUE self)
{
  NSData*      data = unwrap_nsdata(self);
  const void* bytes = [data bytes];
  NSUInteger length = [data length];
  return rb_enc_str_new(bytes, length, rb_utf8_encoding());
}

#writeToFile(*args) ⇒ Object



710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
# File 'ext/accessibility/bridge/bridge.c', line 710

static
VALUE
rb_data_write_to_file(int argc, VALUE* argv, VALUE self)
{
  if (argc < 2)
    rb_raise(
	     rb_eArgError,
	     "wrong number of arguments, got %d, expected 2",
	     argc
	     );

  NSString* path = unwrap_nsstring(argv[0]);
  BOOL    result = [unwrap_nsdata(self) writeToFile:path
		                         atomically:(argv[1] == Qtrue)];

  [path release];

  return (result ? Qtrue : Qfalse);
}