how should I read data from file if size return is logical size of file

Discussion in 'Mac Programming' started by pallavi0703, Jun 26, 2008.

  1. pallavi0703
    Expand Collapse
    macrumors newbie

    pallavi0703

    Joined:
    Dec 12, 2007
    #1
    Hello All,
    I want to get the size of the file. So I am using function

    result = FSOpenFork(&ref, dataForkName.length, dataForkName.unicode, fsRdPerm, &forkRefNum);
    result = FSGetForkSize(forkRefNum, &forkSize);
    result = GetEOF(forkRefNum,&lfrksz);

    both the functions returns filesize as 998 bytes but on disk file size shown is 4 KB that is 406 bytes.
    forksize written is logical size , but how should I read the data from file. I am using. I could not understand that how should I treat the logical size, if data stored in file is serial bytes.
    forkData =(void *)malloc(forkSize);
    if (forkData != NULL)
    {
    Err1= FSReadFork(forkRefNum,fsFromStart,0, forkSize,&forkData, &actualCount);
    }


    if suppose f1.txt is
    6790
    8967
    4035
    etc.
     
  2. Shogododdo
    Expand Collapse
    macrumors member

    Joined:
    Apr 25, 2008
    #2
    Firstly I assume you mean the file size stated is 4096 (4K).

    The disk is probably configured to write the minimum of a disk block, which in your case is 4K is length.

    Having said that, I wouldn't develop file IO code that looped around for 4k bytes to acquire the data.

    You need to develop a looping structure that break out of the loop when you are given the end of file (EOF) signal.

    I'm a newbie to cocoa so in low level terms I dont know the correct calls to make. However, from what I have read it seems like you need to use the methods of NSDocument to perform archiving (writing data) and unarchiving (reading data).

    Shogo.
     
  3. pallavi0703
    Expand Collapse
    thread starter macrumors newbie

    pallavi0703

    Joined:
    Dec 12, 2007
    #3
    Hello Shogododdo ,
    Thanks for reply.
    But what you are assuming is wrong.
    physical size on disk of a file is 4 KB (406 bytes) and
    logical size returned by result = FSGetForkSize(forkRefNum, &forkSize); is 998.
     
  4. Shogododdo
    Expand Collapse
    macrumors member

    Joined:
    Apr 25, 2008
    #4
    That is not 4K.

    4K = 4 x 1024 = 4096 (not 406)
    I was assuming there was a typo in your initial posting.

    Investigate NSDocument, better still get yourself a copy of Aaron Hillegass's excellent book ... Cocoa Programming for Mac OSX.

    Shogo
     
  5. pallavi0703
    Expand Collapse
    thread starter macrumors newbie

    pallavi0703

    Joined:
    Dec 12, 2007
    #5
    Hello Shogododdo ,
    Thanks for reply.
    I am extremely sorry.
    You may laugh on me , because I was passing different file ref and looking at another path file for its size.

    Sorry for this stupid question.
    Now I am getting logical file size = physical size = 406 bytes.
    And I am able read file data properly.
     

Share This Page