[ cl-cookbook-Patches-1522710 ] File Slurping

"SourceForge.net" <[email protected]> Mon, 17 Jul 2006 06:09:48 -0700
Newsgroups gmane.lisp.cookbook
Message-ID <[email protected]>
Patches item #1522710, was opened at 2006-07-14 11:12
Message generated for change (Comment added) made by nobody
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=447474&aid=1522710&group_id=46815

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Widget (example)
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Nobody/Anonymous (nobody)
Assigned to: Nobody/Anonymous (nobody)
Summary: File Slurping

Initial Comment:
I looked through the file section of the cookbook and
found no simple way to get the string contents from a
text file.  

with the-file being a pathname, this snippet returns
the string contents of a file:

  (with-open-file (f the-file)
    (let ((seq (make-string (file-length f))))
        (read-sequence seq f)
        (coerce seq 'string))
      )

I added the coerce at the bottom, but got the main part
from http://www.emmett.ca/~sabetts/slurp.html


According to this article, this is also the fastest.

----------------------------------------------------------------------

Comment By: Nobody/Anonymous (nobody)
Date: 2006-07-17 06:09

Message:
Logged In: NO 

The above leaves extra characters at end of string.  From
what I read it looks like it has something to do with
linefeeds in ms-dos/windows.  This code works with the file
I'm testing (got it from
http://www.codecomments.com/archive274-2006-1-786774.html):

(defun slurp-file (name)
"Slurps up file <name> and returns the data as a string."
(let ((data nil))
(with-open-file (file name :direction :input)
(setf data (make-array (file-length file) :element-type
'character
:fill-pointer t :adjustable t))
(setf (fill-pointer data) (read-sequence data file))
(values data))))


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=447474&aid=1522710&group_id=46815


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642