$PBExportHeader$f_blobtofile.srf
global type f_blobtofile from function_object
end type

forward prototypes
global function integer f_blobtofile (string arg_filepathname, blob arg_blobdata, ref string arg_msg)
end prototypes

global function integer f_blobtofile (string arg_filepathname, blob arg_blobdata, ref string arg_msg);//blob转文件
long rslt=1,fend,fend_t
blob b_dtdata, b_dtdata_p
long li_FileNum,ls_i,ls_jh
string tmpfilepathname

tmpfilepathname=arg_filepathname
b_dtdata=arg_blobdata

fend=len(b_dtdata)
	if fend<=32765 then
		fend_t=1
	else
		fend_t=fend/32765
		if mod(fend,32765)<>0 then
			fend_t=fend_t+1
		end if
	end if
	li_FileNum = FileOpen( tmpfilepathname,StreamMode!, Write!, LockWrite!)
	if li_FileNum<=0 then
		arg_msg="打开文件"+tmpfilepathname+"失败"
		rslt=0
		fileclose(li_FileNum)
		goto ext
	end if
	for ls_i = 1 to fend_t
		b_dtdata_p=blobmid(b_dtdata,1+(ls_i - 1 )*32765,32765)

		ls_jh=FileWrite(li_FileNum, b_dtdata_p)
		if ls_jh<=0 then
			arg_msg="写文件"+tmpfilepathname+"失败"
			rslt=0
			fileclose(li_FileNum)
			goto ext
		end if
	next
	fileclose(li_FileNum)

ext:
return rslt
end function

