Байты “N” только для чтения из файла в Какао

С помощью aws cli можно скопировать всю папку в корзину.

aws s3 cp /path/to/folder s3://bucket/path/to/folder --recursive

Существует также опция синхронизации папки с помощью aws s3 sync

.

18
задан Grzegorz Kazulak 1 June 2009 в 18:14
поделиться

4 ответа

If you want random access to the contents of the file in a manner similar to having loaded it via NSData but without actually reading everything into memory, you can use memory mapping. Doing so means that the file on disk becomes treated as a section of virtual memory, and will be paged in and out just like regular virtual memory.

NSError * error = nil;
NSData * theData = [NSData dataWithContentsOfFile: thePath
                                          options: NSMappedRead
                                            error: &error];

If you don't care about getting filesystem error details, you can just use:

NSData * theData = [NSData dataWithContentsOfMappedFile: thePath];

Then you would just use NSData's -getBytes:range: method to pull out specific pieces of data, and only the relevant parts of the file will actually be read from permanent storage; they'll also be eligible to be paged out too.

26
ответ дан 30 November 2019 в 06:17
поделиться

Если вы хотите избежать чтения всего файла, вы можете просто использовать стандартные функции CI / O:

#include <stdio.h>
...
FILE *file = fopen("the-file.dat", "rb");
if(file == NULL)
    ; // handle error
char theBuffer[1000];  // make sure this is big enough!!
size_t bytesRead = fread(theBuffer, 1, 1000, file);
if(bytesRead < 1000)
    ; // handle error
fclose(file);
3
ответ дан 30 November 2019 в 06:17
поделиться

- [NSFileHandle readDataOfLength:] .

NSFileHandle *handle = [NSFileHandle fileHandleForReadingAtPath:filePath];
NSData *fileData = [handle readDataOfLength:N];
[handle closeFile];
24
ответ дан 30 November 2019 в 06:17
поделиться

Откройте файл:

NSData *fileData = [NSData dataWithContentsOfFile:fileName];

Прочтите нужные байты:

int bytes[1000];
[fileData getBytes:bytes length:sizeof(int) * 1000];
0
ответ дан 30 November 2019 в 06:17
поделиться