AjBool gHttpGetBinS(AjPStr url, AjPFile* outf) { AjPFile file = NULL; AjPStr line = NULL; AjPStr host = NULL; AjPStr path = NULL; AjPStr get = NULL; ajint port = 80; ajuint http = 0; FILE *fp; AjPRegexp crlf = NULL; char buf[8]; AjOSysSocket sock; get = ajStrNew(); ajHttpUrlDeconstruct(url, &port, &host, &path); while(file==NULL || gHttpRedirect(file, &host, &port, &path)) { if(ajStrGetCharFirst(path) != '/') ajStrInsertK(&path, 0, '/'); ajFmtPrintS(&get, "GET http://%S:%d%S HTTP/1.1\r\n", host, port, path); fp = ajHttpOpen(NULL, host, port, get, &sock); file = ajFileNewFromCfile(fp); if(!file) return ajFalse; } ajStrDel(&get); crlf = ajRegCompC("^\r?\n$"); while(ajReadline(file, &line)) { if(ajRegExec(crlf, line)) break; } while(ajReadbinBinary(file, 1, 1, buf)) { ajWritebinBinary(*outf, 1, 1, buf); } ajFileClose(outf); ajFileClose(&file); return ajTrue; }
static size_t dbiblast_memfread(void* dest, size_t size, size_t num_items, PMemFile mf) { size_t i; if(mf->IsMem) { /* memory mapped */ i = size * num_items; memcpy(dest, &mf->Mem[mf->Pos], i); mf->Pos += (ajlong) i; return i; } return ajReadbinBinary(mf->File, num_items, size, dest); }
/* @obsolete ajFileRead ** @replace ajReadbinBinary (1,2,3,4/4,3,2,1) */ __deprecated size_t ajFileRead(void* ptr, size_t element_size, size_t count, AjPFile file) { return ajReadbinBinary(file, count, element_size, ptr); }