2007-03-02 01:36:52 +00:00
|
|
|
//
|
|
|
|
// FileSource.m
|
|
|
|
// FileSource
|
|
|
|
//
|
|
|
|
// Created by Vincent Spader on 3/1/07.
|
|
|
|
// Copyright 2007 __MyCompanyName__. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "FileSource.h"
|
|
|
|
|
|
|
|
|
|
|
|
@implementation FileSource
|
|
|
|
|
|
|
|
- (BOOL)open:(NSURL *)url
|
|
|
|
{
|
2007-10-14 18:12:15 +00:00
|
|
|
_url = url;
|
|
|
|
[_url retain];
|
2007-03-04 04:36:10 +00:00
|
|
|
|
2007-03-02 01:36:52 +00:00
|
|
|
_fd = fopen([[url path] UTF8String], "r");
|
|
|
|
|
|
|
|
return (_fd != NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)seekable
|
|
|
|
{
|
2007-03-04 00:18:28 +00:00
|
|
|
return YES;
|
2007-03-02 01:36:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)seek:(long)position whence:(int)whence
|
|
|
|
{
|
|
|
|
return (fseek(_fd, position, whence) == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (long)tell
|
|
|
|
{
|
|
|
|
return ftell(_fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int)read:(void *)buffer amount:(int)amount
|
|
|
|
{
|
|
|
|
return fread(buffer, 1, amount, _fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)close
|
|
|
|
{
|
2007-10-14 18:12:15 +00:00
|
|
|
[_url release];
|
|
|
|
_url = nil;
|
2007-10-13 07:09:46 +00:00
|
|
|
|
2007-10-15 03:29:30 +00:00
|
|
|
if (_fd)
|
|
|
|
{
|
|
|
|
fclose(_fd);
|
|
|
|
_fd = NULL;
|
|
|
|
}
|
2007-03-02 01:36:52 +00:00
|
|
|
}
|
|
|
|
|
2007-03-04 04:36:10 +00:00
|
|
|
- (NSURL *)url
|
|
|
|
{
|
|
|
|
return _url;
|
|
|
|
}
|
|
|
|
|
2007-10-14 18:12:15 +00:00
|
|
|
- (NSString *)mimeType
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2007-03-04 04:36:10 +00:00
|
|
|
- (void)setURL:(NSURL *)url
|
|
|
|
{
|
|
|
|
[url retain];
|
|
|
|
[_url release];
|
|
|
|
_url = url;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-03-02 01:36:52 +00:00
|
|
|
+ (NSArray *)schemes
|
|
|
|
{
|
|
|
|
return [NSArray arrayWithObject:@"file"];
|
|
|
|
}
|
|
|
|
|
2007-10-13 07:09:46 +00:00
|
|
|
- (void)dealloc {
|
2007-10-15 03:29:30 +00:00
|
|
|
[self close];
|
2007-10-13 07:09:46 +00:00
|
|
|
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2007-03-02 01:36:52 +00:00
|
|
|
@end
|