Skip to content
Browse files

Initial IO support

  • Loading branch information...
1 parent 27a401f commit 2f531a28157a1e2557f5583da3b620ed0c9162eb @cfjedimaster cfjedimaster committed May 25, 2012
Showing with 73 additions and 0 deletions.
  1. +1 −0 docs/generate.cfm
  2. +36 −0 sesame/io.cfm
  3. +36 −0 tests/cases/IOTest.cfc
View
1 docs/generate.cfm
@@ -85,6 +85,7 @@ that need to be instantiated to interact with the Java concurrency libraries.
{file = "collections.cfm", title="Collections", description="Functions that allow you manipulate and use structs and arrays much easier"}
,{file = "functions.cfm", title="Functions", description="Functions that allow you to manipulate other functions / closures"}
,{file = "numbers.cfm", title="Numbers", description="Functions for working with numbers and general looping"}
+ ,{file = "io.cfm", title="IO", description="Functions for working with input/output"}
,{file = "concurrency.cfm", title="Concurrency", description=concurrencyDesc}
];
</cfscript>
View
36 sesame/io.cfm
@@ -0,0 +1,36 @@
+<!---
+ Copyright 2012 Raymond Camden
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+ Functions pertaining to input/output
+--->
+
+<cfscript>
+
+ /**
+ * Read a file and call the closure on each line. Works on either a file ob or path
+ *
+ * @file the file to load
+ * @handler closure to take the input
+ */
+ public void function _fileLineEach(required any file, required function handler)
+ {
+ if(isSimpleValue(arguments.file)) arguments.file = fileOpen(arguments.file);
+ while(!fileIsEOF(arguments.file)) {
+ var line = fileReadLine(arguments.file);
+ handler(line);
+ }
+ };
+
+</cfscript>
View
36 tests/cases/IOTest.cfc
@@ -0,0 +1,36 @@
+/**
+ * Test for io
+ */
+component extends="tests.AbstractTestCase"
+{
+ include "../../sesame/io.cfm";
+
+ /**
+ * test fileLineEach
+ */
+ public void function testFileLineEach()
+ {
+ var buffer = "";
+ var theFile = getCurrentTemplatePath();
+ _fileLineEach(theFile, function(line) {
+ buffer &= line;
+ });
+
+ assertTrue(find("_fileReadLine", buffer));
+ }
+
+ /**
+ * test fileLineEach with a file ob
+ */
+ public void function testFileLineEachObject()
+ {
+ var buffer = "";
+ var theFile = fileOpen(getCurrentTemplatePath());
+ _fileLineEach(theFile, function(line) {
+ buffer &= line;
+ });
+
+ assertTrue(find("_fileReadLine", buffer));
+ }
+
+}

0 comments on commit 2f531a2

Please sign in to comment.
Something went wrong with that request. Please try again.