Class: NSData
- 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
-
.data ⇒ Object
TODO: implement commented out methods.
-
.dataWithContentsOfURL(url) ⇒ Object
rb_define_singleton_method(rb_cData, "dataWithContentsOfFile", rb_data_with_contents_of_file, 1);.
Instance Method Summary collapse
-
#isEqualToData(other) ⇒ Object
(also: #==)
rb_define_method(rb_cData, "subdataWithRange", rb_data_subrange, 1);.
- #length ⇒ Object
-
#to_str ⇒ Object
rb_define_method(rb_cData, "writeToURL", rb_data_write_to_url, -1);.
- #writeToFile(, self) ⇒ Object
Class Method Details
.data ⇒ Object
TODO: implement commented out methods
652 653 654 655 656 657 |
# File 'ext/accessibility/bridge/bridge.c', line 652
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);
659 660 661 662 663 664 665 666 667 |
# File 'ext/accessibility/bridge/bridge.c', line 659
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);
676 677 678 679 680 681 |
# File 'ext/accessibility/bridge/bridge.c', line 676
static
VALUE
rb_data_equality(const VALUE self, const VALUE other)
{
OBJC_EQUALITY(rb_cData, unwrap_nsdata);
}
|
#length ⇒ Object
669 670 671 672 673 674 |
# File 'ext/accessibility/bridge/bridge.c', line 669
static
VALUE
rb_data_length(const VALUE self)
{
return ULONG2NUM([unwrap_nsdata(self) length]);
}
|
#to_str ⇒ Object
rb_define_method(rb_cData, "writeToURL", rb_data_write_to_url, -1);
702 703 704 705 706 707 708 709 710 |
# File 'ext/accessibility/bridge/bridge.c', line 702
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
683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 |
# File 'ext/accessibility/bridge/bridge.c', line 683
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);
}
|