Archive of UserLand's first discussion group, started October 5, 1998.
What is html.writeFile?
Author: Brent Simmons Posted: 12/10/1998; 1:37:11 PM Topic: What is html.writeFile? Msg #: 1098 Prev/Next: 1097 / 1099
Html.writeFile is an important verb that hasn't been documented until now. New DocServer page:
This is the verb to use when, in your website macros and filters, you want to write a file.
It's important because this verb allows you to not have to know where the file is eventually going. You don't have to know how the file will get there. No matter how or where it's going, you always call html.writeFile.
A file may be going to disk, to an FTP server, to an object database, or somewhere else. Html.writeFile lets you pretend that it's going to disk, no matter where it's really going.
This verb was introduced with 5.1, it's part of the new fileWriters abstraction layer. (A page about that will appear soon, and I'll edit in a link here.)
Say you want to write a file that should go in the same folder as the page being rendered. (No matter where that folder is, on whatever machine. Maybe it's not a folder but a table. It doesn't matter.)
Your macro would contain code like this:
local (adrPageTable = html.getPageTableAddress ())
local (folder = file.folderFromPath (adrPageTable^.f))
local (myFileName = "My File.txt")
local (myFilePath = folder myFileName)
local (myFileContents = "This will be the contents of my file.")
html.writeFile (f, @s, 'TEXT', 'R*ch', clock.now (), adrPageTable)
Html.writeFile may or may not cause the file to be written to disk -- it will cause the file to get sent to the right place via the right transport method, whether it's FTP or whatever.
Note that a file doesn't have to be a text file: it can be any kind of binary file, too.
Under the hood, html.writeFile works by telling the current fileWriter to write a file. The fileWriter then handles all the details of getting the file to the right place.
You specify the fileWriter to use in the method field of your #ftpSite table. More about #ftpSite:
When a page is being rendered behind a webserver -- when it's a dynamic page -- html.writeFile returns right away. No file gets written. This is because dynamic pages and files are returned to a browser as a result of an HTTP request; they're not "pushed" to a location on a server.
This page was archived on 6/13/2001; 4:46:27 PM.
© Copyright 1998-2001 UserLand Software, Inc.