views:

54

answers:

2

Hi,

I'm trying to download http://www.vesseltracker.com/earth/vesseltrackerlight.kmz but am not getting all the bits and pieces.

I tried:

  NSData *data = [NSData dataWithContentsOfURL: serverURL options: 0 error: &error];

to no avail

then switched to

- (void)startDownloadingURL:(NSURL*) url
{
    // Create the request.
    NSURLRequest *theRequest = [NSURLRequest requestWithURL:url
            cachePolicy:NSURLRequestUseProtocolCachePolicy
           timeoutInterval:60.0];

    // create the connection with the request
 // and start loading the data
 NSLog(@"SNNetworkController.startDownloadingURL [%@]", url);
 NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
 if (theConnection) {
  // Create the NSMutableData to hold the received data.
  // receivedData is an instance variable declared elsewhere.
  receivedData = [[NSMutableData data] retain];
    } else {
        // inform the user that the download failed.
  NSLog(@"SNNetworkController.startDownloadingURL Download failed!");
    }
}

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
    // This method is called when the server has determined that it
    // has enough information to create the NSURLResponse.

    // It can be called multiple times, for example in the case of a
    // redirect, so each time we reset the data.

    // receivedData is an instance variable declared elsewhere.
    [receivedData setLength:0];
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
    // Append the new data to receivedData.
    // receivedData is an instance variable declared elsewhere.
    [receivedData appendData:data];
}

- (void)connection:(NSURLConnection *)connection
  didFailWithError:(NSError *)error
{
    // release the connection, and the data object
    [connection release];
    // receivedData is declared as a method instance elsewhere
    [receivedData release];

    // inform the user
    NSLog(@"SNNetworkController.didFailWithError Download failed! Error - %@",
          [error localizedDescription]);
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    // do something with the data
    // receivedData is declared as a method instance elsewhere
    NSLog(@"SNNetworkController.downloadDidFinish Succeeded! Received %d bytes of data",[receivedData length]);

    // release the connection, and the data object
    [connection release];
    [receivedData release];
}

But I am out of luck. It always takes 567 bytes (should be around 4k) I think it may start to decompress and fail....

+1  A: 

I downloaded the URL you listed with Safari and it is only 567 bytes long. Are you basing your "4k" expectation on what the Finder list view says? That display is only approximate due to file allocation block sizes... The actual byte count of the file is displayed in parenthesis behind that value in the "Get Info..." window for the file.

GoannaGuy
I downloaded it with curl and got the same result, so it's not something WebKit-/Foundation-specific; it appears that the file being served up by the server really is only 567 bytes.
Peter Hosey
A: 

I feel quite dumb now :-( you guys are right. Actual file size is 567 bytes, size on disk is 4kb, the finder has mislead me, i should have checked with ls.

Thanks for your responses, next step is to figure out how to decompress this thing.

Regards,

Chris

CocoaChris