//file 网络文件流
//仅供 inet.http,inet.ftp 调用
 
namespace inet.file;

InternetReadFile = Wininet.api("InternetReadFile"
,"bool(POINTER hFile, string &lpBuffer, INT bytes, INT &bytesRead)");

InternetWriteFile = Wininet.api("InternetWriteFile"
	,"bool(POINTER hFile, string lpBuffer, INT len, INT &bytesWritten)")
		
write = function( hFile, str,...){
	var ok,len = InternetWriteFile(hFile,str,#str,0);
	if(!ok)return;
	if(!...)return len;
	return len + write( hFile,... );
};

read = function( hFile, bufferSize = 1024 ){
	var ok,str,size = InternetReadFile(hFile,bufferSize ,bufferSize,0); 
	
	if(!ok)   
		return null,..lasterr(,"InternetReadFile") 
    
	if ( size ) 
		return ..string.left(str,size),size; 
};  
