KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Appending a blob at the front of a second blob
PRODUCT: 4D | VERSION: 2003 | PLATFORM: Mac & Win
Published On: May 20, 2004
Your current browser may not allow you to download the asset. We recommend Mozilla Firefox or Google Chrome.
Log In

Here is a neat little tech tip that demonstrates how to insert a blob into the beginning of another blob. This might be useful in a client/server environment where you need to append header information to the body of a message to be sent via http or another protocol.

  `Declaration of parameters
C_BLOB($0;$header)
C_BLOB($1;$body)
C_LONGINT($headersize;$size)
C_TEXT($response;$crlf)

  `Assigning variables
$crlf:=Char(Carriage return )+Char(Line feed)
$body:=$1
$size:=BLOB size($body)

  `Building the http header
$response:="HTTP/1.0 200 OK"+$crlf
$response:=$response+"ACCEPT-Ranges: bytes"+$crlf
$response:=$response+Get_Date +$crlf
$response:=$response+"Content-Length: "+String($size)+$crlf
$response:=$response+"Content-Type: text/html"+$crlf
$response:=$response+"Server: 4D ical Server"+$crlf+$crlf

  `Converting the http header into a blob and then calculating the size of the header
TEXT TO BLOB($response;$header;Text without length)
$headersize:=BLOB size($header)

  `Insert into the beginning of the body blob, the number of bytes of the header blob
INSERT IN BLOB($body;0;$headersize)

  `Copies the beginning of the header blob into the beginning of the body blob
COPY BLOB($header;$body;0;0;$headersize)

$0:=$body

  `Clean up blobs
SET BLOB SIZE($header;0)
SET BLOB SIZE($body;0)