Esempio n. 1
0
File: supoo.c Progetto: dyama/supoo
int main(int argc, char const* argv[])
{
  if (argc != 2) {
    printf("usage: %s file\n", argv[0]);
    return 0;
  }

  char* str = read_to_end(argv[1]);
  if (str == NULL) {
    return 1;
  }

  value code;
  if (parse(str, &code)) {
    free(str);
    return 2;
  }
  free(str);

  value arena;
  arena_begin(&arena);
  exec(&arena, &code, NULL);
  arena_end(&arena);

  return 0;
}
    TEST_FIXTURE(page_blob_test_base, page_blob_file_upload)
    {
        azure::storage::blob_request_options options;
        options.set_store_blob_content_md5(true);

        utility::string_t md5_header;
        m_context.set_sending_request([&md5_header] (web::http::http_request& request, azure::storage::operation_context)
        {
            if (!request.headers().match(U("x-ms-blob-content-md5"), md5_header))
            {
                md5_header.clear();
            }
        });

        temp_file invalid_file(1000);
        CHECK_THROW(m_blob.upload_from_file(invalid_file.path(), 0, azure::storage::access_condition(), options, m_context), azure::storage::storage_exception);

        temp_file file(1024);
        m_blob.upload_from_file(file.path(), 0, azure::storage::access_condition(), options, m_context);
        CHECK_UTF8_EQUAL(file.content_md5(), md5_header);

        m_context.set_sending_request(std::function<void(web::http::http_request &, azure::storage::operation_context)>());

        temp_file file2(0);
        m_blob.download_to_file(file2.path(), azure::storage::access_condition(), options, m_context);

        concurrency::streams::container_buffer<std::vector<uint8_t>> original_file_buffer;
        auto original_file = concurrency::streams::file_stream<uint8_t>::open_istream(file.path()).get();
        original_file.read_to_end(original_file_buffer).wait();
        original_file.close().wait();

        concurrency::streams::container_buffer<std::vector<uint8_t>> downloaded_file_buffer;
        auto downloaded_file = concurrency::streams::file_stream<uint8_t>::open_istream(file2.path()).get();
        downloaded_file.read_to_end(downloaded_file_buffer).wait();
        downloaded_file.close().wait();

        CHECK_EQUAL(original_file_buffer.collection().size(), downloaded_file_buffer.collection().size());
        CHECK_ARRAY_EQUAL(original_file_buffer.collection(), downloaded_file_buffer.collection(), (int)downloaded_file_buffer.collection().size());

        m_blob.properties().set_content_md5(dummy_md5);
        m_blob.upload_properties();
        options.set_retry_policy(azure::storage::no_retry_policy());
        CHECK_THROW(m_blob.download_to_file(file2.path(), azure::storage::access_condition(), options, m_context), azure::storage::storage_exception);
    }
Esempio n. 3
0
void cue_from_file(struct cue *cue, const char *filename) {

    FILE *cuefile;
    char *cuebuf, *token;
    unsigned trackno;

    cuefile = fopen(filename, "r");
    if(!cuefile) {
        fprintf(stderr, "Couldn't open \"%s\". Sorry.\n", filename);
        exit(EXIT_FAILURE);
    }
    cuebuf = read_to_end(cuefile);
    fclose(cuefile);


    struct cuetrack *track = NULL;
    cue->numtracks = 0;
    cue->tracks = NULL;

    token = strtok(cuebuf, " \r\n");

    while(token) {

        if(!strcmp(token, "PERFORMER")) {
            strncpy(track ? track->performer : cue->performer, strtok(NULL, "\""), 256);
        } else if(!strcmp(token, "TITLE")) {
            strncpy(track ? track->title : cue->title, strtok(NULL, "\""), 256);
        } else if(!strcmp(token, "FILE")) {
            strncpy(cue->filename, strtok(NULL, "\""), 256);
        } else if(!strcmp(token, "TRACK")) {
            ++(cue->numtracks);
            cue->tracks = realloc(cue->tracks, cue->numtracks*sizeof(struct cuetrack));
            track = cue->tracks + cue->numtracks - 1;
            track->trackno = strtoul(strtok(NULL, " \r\n"), NULL, 10);
        } else if(!strcmp(token, "INDEX")) {
            strtok(NULL, " \r\n");
            track->index_ms = 60*1000*strtoul(strtok(NULL, ":"), NULL, 10);
            track->index_ms += 1000*strtoul(strtok(NULL, ":"), NULL, 10);
            track->index_ms += strtod(strtok(NULL, " \r\n"), NULL)*1000.0/100.0;
        }

        token = strtok(NULL, " \r\n");
    }

    free(cuebuf);
}
    TEST_FIXTURE(block_blob_test_base, blob_read_stream_download)
    {
        azure::storage::blob_request_options options;
        options.set_stream_read_size_in_bytes(1 * 1024 * 1024);
        options.set_use_transactional_md5(true);

        std::vector<uint8_t> buffer;
        buffer.resize(3 * 1024 * 1024);
        fill_buffer_and_get_md5(buffer);
        m_blob.upload_from_stream(concurrency::streams::bytestream::open_istream(buffer), azure::storage::access_condition(), options, m_context);

        concurrency::streams::container_buffer<std::vector<uint8_t>> output_buffer;

        auto stream = m_blob.open_read(azure::storage::access_condition(), options, m_context);
        stream.read_to_end(output_buffer).wait();
        stream.close().wait();

        CHECK_EQUAL(buffer.size(), output_buffer.collection().size());
        CHECK_ARRAY_EQUAL(buffer, output_buffer.collection(), (int)output_buffer.collection().size());
    }