Yep most common file types are covered by the magic file, though there are a 
ton of types, and many are identified by different means whether a byte 
sequence in an established location or a string or otherwise. 

The more control you have over what files you receive over the wire, in what 
order and in what naming convention etc.. The more you can simplify the 
approach and handling. 

In the end, the only way to truly verify a file is what you expect it to be is 
to read it. 
You always should handle an error in finding or reading the file. 

Extensions tell you nothing unless it is trusted data you control. 
Mime types are also really just a promise. 

Sent from my iPhone

> On 2013/09/29, at 15:31, Charles Srstka <cocoa...@charlessoft.com> wrote:
> 
> It will work fine for an iOS app, if you use the contents of the files in 
> /usr/share/file/magic/ to understand the formats of the files you want to 
> identify and use that knowledge to identify the files by looking at the bytes 
> of the NSData object. A lot of the time there's a sequence of bytes called 
> the "magic number" right at the beginning of the file that identify it. If 
> you look at the magic files, you can see how the 'file' program determines 
> certain types of files, and then you can do the same thing in your app.
> 
> Depending on what you're doing, copying the whole file program is probably 
> overkill IMO.
> 
> Charles
> 
>> On Sep 29, 2013, at 12:17 AM, Maxthon Chan <xcvi...@me.com> wrote:
>> 
>> It will not work for iOS app. However you can include your own copy of 
>> file(1) utility in your code. It is open sourced so you can make it part of 
>> your code.
>> 
>>> On Sep 29, 2013, at 5:34, Devarshi Kulshreshtha 
>>> <devarshi.bluec...@gmail.com> wrote:
>>> 
>>> Thanks, will check for sure.. one more query.. will it be applicable in an
>>> ios app? Mine is an iOS app.
>>> 
>>> 
>>> On Sat, Sep 28, 2013 at 4:29 PM, Charles Srstka 
>>> <cocoa...@charlessoft.com>wrote:
>>> 
>>>> On Sep 28, 2013, at 4:17 PM, Devarshi Kulshreshtha <
>>>> devarshi.bluec...@gmail.com> wrote:
>>>> 
>>>>> 1. Is there any other way to identify file extension for the files
>>>> without
>>>>> extensions, say from NSData object?
>>>> 
>>>> Have a look at the files in /usr/share/file/magic/ to get some ideas of
>>>> how to identify various types of files.
>>>> 
>>>> Charles
>>>> 
>>>> _______________________________________________
>>>> 
>>>> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>>>> 
>>>> Please do not post admin requests or moderator comments to the list.
>>>> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>>>> 
>>>> Help/Unsubscribe/Update your Subscription:
>>>> 
>>>> https://lists.apple.com/mailman/options/cocoa-dev/devarshi.bluechip%40gmail.com
>>>> 
>>>> This email sent to devarshi.bluec...@gmail.com
>>> 
>>> 
>>> 
>>> 
>>> -- 
>>> Thanks,
>>> 
>>> Devarshi
>>> _______________________________________________
>>> 
>>> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>>> 
>>> Please do not post admin requests or moderator comments to the list.
>>> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>>> 
>>> Help/Unsubscribe/Update your Subscription:
>>> https://lists.apple.com/mailman/options/cocoa-dev/xcvista%40me.com
>>> 
>>> This email sent to xcvi...@me.com
> 
> ______________________________________________

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to