CFLib.org – Common Function Library Project

WDDXFileRead(file)

Last updated October 15, 2002

Version: 2 | Requires: ColdFusion MX | Library: CFMLLib

 
Rated 1 time(s). Average Rating: 5.0

Description:
Ever get annoyed at the couple of lines you are always writing to store and retrieve WDDX in flat files? Then this is the UDF for you. Also see it's sister UDF WDDXFileWrite()

Return Values:
Returns deserialized data.

Example:

view plain print about
<cfscript>
    hello = structNew();
    hello.foo.bar = 2;
    hello.thing = "a string";
//    wddxfileWrite(expandPath("test.wddx"),hello);
//    stuff = WDDXFileRead(expandPath("test.wddx"));
</cfscript>
<!---
<cfdump var="#stuff#">
--->

Parameters:

Name Description Required
file File to read and deserialize. Yes

Full UDF Source:

view plain print about
<!---
 Reads a file containing WDDX and returns the CF variable.
 Updated for CFMX var scope syntax.
 
 @param file      File to read and deserialize. (Required)
 @return Returns deserialized data. 
 @author Nathan Dintenfass (nathan@changemedia.com) 
 @version 2, October 15, 2002 
--->

<cffunction name="WDDXFileRead" output="no">
    <cfargument name="file" required="yes">
    
    <cfset var tempPacket = "">
    <cfset var tempVar = "">
    
    <!--- make sure the file exists, otherwise, throw an error --->
    <cfif NOT fileExists(file)>
        <cfthrow message="WDDXFileRead() error: File Does Not Exist" detail="The file #file# called in WDDXFileRead() does not exist">
    </cfif>
    <!--- read the file --->
    <cffile action="read" file="#file#" variable="tempPacket">
    <!--- make sure it is a valid WDDX Packet --->
    <cfif NOT isWDDX(tempPacket)>
        <cfthrow message="WDDXFileRead() error: Bad Packet" detail="The file #file# called in WDDXFileRead() does not contain a valid WDDX packet">        
    </cfif>
    <!--- deserialize --->
    <cfwddx action="wddx2cfml" input="#tempPacket#" output="tempVar">
    <cfreturn tempVar>    
</cffunction>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Dave Anderson Dave Anderson added
iniToStruct
20 day(s) ago

Dave Anderson Dave Anderson added
deDupeArray
20 day(s) ago

Richard Richard added
dice
22 day(s) ago

Isaac Dealey Isaac Dealey added
getRelative
a while ago

Top Rated

Darwan Leonardo Sitepu backupDatabase
Rated 5.0, 22 time(s)

Barney Boisvert indentXml
Rated 5.0, 10 time(s)

Kevin Pepperman generateSsccAsn
Rated 5.0, 4 time(s)

Raymond Camden highlightAndCrop
Rated 5.0, 4 time(s)

Created by Raymond Camden / Design by Justin Johnson