0 Replies Latest reply: Apr 4, 2011 11:45 AM by Scot Junkin RSS

Extracting pieces of objects using C wrappers

Scot Junkin

This is a simple program which shows how to use the c wrappers to extract a chunk/byte range of an object within the namespace on an Atmos system.

{sample execution}

./a.out object_name starting_byte total_bytes

 

Here is a sample run pulling 32 bytes from offset 31 of the object atmos.js living within my namespace at /atmos.js:

 

sjunkin@dev-ubuntu$ ./atmostest atmos.js 31 32
urn new Date().toGMTString();

 

Below is the code in C I used - it needs to be linked against the c wrappers.  The important codebits here are the rd.offset and rd.body_size which dictate where and how much of the object to bring back.

 

This code gets translated by the wrapper code into the HTTP header

range: Bytes=(offset)-(offset+total_bytes-1)

which is passed with the GET request in the wrappers to the Atmos system.

 

 

sdj

 

---**code**--

 

int main(int argc, char **argv) {
    credentials *c = init_ws(user_id, key, endpoint);
    ws_result result, result2;

    char *testfile=argv[1];
    system_meta sm;
    user_meta *um = NULL;
    postdata rd;

    memset(&rd, 0, sizeof(rd));
    rd.offset=atoi(argv[2]);
    rd.body_size=atoi(argv[3]);
    list_ns(c, testfile,&rd, 0, &result);
    memset(&sm, 0, sizeof(sm));
    parse_headers(&result, &sm, &um);
    while(um != NULL) {
        user_meta *t = um->next;
        free(um);
        um=t;
    }

    char *output ;

    output = (char*)malloc(result.body_size+1);

    memcpy(output,result.response_body,result.body_size);

    output[result.body_size] = '\0';

    printf("%s\n", output);

    free(output);

    result_deinit(&result);

    free(c);

}