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



660
661
662
663
664
665
# File 'ext/accessibility/bridge/bridge.c', line 660

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

.dataWithContentsOfURL(url) ⇒ Object

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



667
668
669
670
671
672
673
674
675
# File 'ext/accessibility/bridge/bridge.c', line 667

static
VALUE
rb_data_with_contents_of_url(const VALUE self, const VALUE url)
{
    NSData* const 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);



684
685
686
687
688
689
# File 'ext/accessibility/bridge/bridge.c', line 684

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

#lengthObject



677
678
679
680
681
682
# File 'ext/accessibility/bridge/bridge.c', line 677

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

#to_strObject

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



710
711
712
713
714
715
716
717
718
# File 'ext/accessibility/bridge/bridge.c', line 710

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

#writeToFile(, self) ⇒ Object



691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
# File 'ext/accessibility/bridge/bridge.c', line 691

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

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

    [path release];

    return (result ? Qtrue : Qfalse);
}