[TIMOB-1656] API inconsistency: TiBlob has 'length' property on Android, 'size' on iOS
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Medium |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2012-05-03T15:47:23.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Release 2.1.0 |
Components | Android |
Labels | core |
Reporter | Brion Vibber |
Assignee | Nolan Wright |
Created | 2011-04-15T02:58:35.000+0000 |
Updated | 2017-03-07T18:19:56.000+0000 |
Description
In StatusNet Mobile, I'm trying to get the byte size of a blob I've read from a file when passing a saved photo from one context to another. The undocumented TiBlob type has a lot of differences in its interface between the iOS and Android implementations, and it's hitting here...
On Android there's a 'length' property:
public int getLength() {
switch (type) {
case TYPE_FILE:
return (int) ((TiBaseFile)data).getNativeFile().length();
case TYPE_DATA:
case TYPE_IMAGE:
return ((byte[])data).length;
default:
// this is probably overly expensive.. is there a better way?
return getBytes().length;
}
}
But on iOS, there's a 'size' property:
-(NSInteger)size {
[self ensureImageLoaded];
if (image!=nil)
{
return image.size.width * image.size.height;
}
switch (type)
{
case TiBlobTypeData:
{
return [data length];
}
case TiBlobTypeFile:
{
NSFileManager *fm = [NSFileManager defaultManager];
NSError *error = nil;
NSDictionary * resultDict = [fm attributesOfItemAtPath:path error:&error];
id result = [resultDict objectForKey:NSFileSize];
if (error!=NULL)
{
return 0;
}
return [result intValue];
}
}
return 0;
}
They also don't have matching behavior for image blobs: Android appears to return the byte size of whatever raw data the image is using (is this source file? uncompressed? what bit depth?), while on iOS it returns the number of pixels in the image. (Shouldn't make a difference in this case though, since I'm reading straight from a saved temporary file.)
Referencing my previous bug on the missing API documentation for the Blob type on mobile:
https://appcelerator.lighthouseapp.com/projects/32238/tickets/1580-titaniumblob-tiblob-missing-from-mobile-api-documentation"> https://appcelerator.lighthouseapp.com/projects/32238/tickets/1580-...
Note that the Desktop docs do have documentation for the Blob type there:
https://developer.appcelerator.com/apidoc/desktop/latest/Titanium.Blob-object"> https://developer.appcelerator.com/apidoc/desktop/latest/Titanium.B...
Desktop's blob type has a 'length' property, matching the Android implementation (though I'm uncertain whether there are image blobs on Desktop, and it doesn't say how it would return a length for those).
Assigning to StatusNet's support contact.
Fixed in master (2.1.0.848d711) at some point. Resolving.
Closing ticket due to time passed.