FileStream.st
changeset 92 0c73b48551ac
parent 88 81dacba7a63a
child 159 514c749165c3
--- a/FileStream.st	Sun Jul 10 00:59:39 1994 +0200
+++ b/FileStream.st	Fri Aug 05 02:55:07 1994 +0200
@@ -20,6 +20,8 @@
 FileStream comment:'
 COPYRIGHT (c) 1989 by Claus Gittinger
               All Rights Reserved
+
+$Header: /cvs/stx/stx/libbasic/FileStream.st,v 1.14 1994-08-05 00:54:46 claus Exp $
 '!
 
 !FileStream class methodsFor:'documentation'!
@@ -40,7 +42,7 @@
 
 version
 "
-$Header: /cvs/stx/stx/libbasic/FileStream.st,v 1.13 1994-06-02 16:20:18 claus Exp $
+$Header: /cvs/stx/stx/libbasic/FileStream.st,v 1.14 1994-08-05 00:54:46 claus Exp $
 "
 !
 
@@ -48,6 +50,10 @@
 "
     This class provides access to the operating systems underlying file
     system (i.e. its an interface to the stdio library).
+
+    Notice, that on some systems, the standard I/O library has performance
+    problems when a file is opened for readwrite. 
+    For best results, open files either readonly or writeonly.
 "
 ! !
 
@@ -87,7 +93,7 @@
 newFileNamed:filename
     "return a FileStream for new file named filename, aString.
      If the file exists, it is truncated, otherwise created.
-     The file is opened for write access only."
+     The file is opened for read/write access."
 
     |newStream|
     newStream := self new pathName:filename.
@@ -99,7 +105,7 @@
     "return a FileStream for new file named filename, aString
      in aDirectory, a FileDirectory.
      If the file exists, it is truncated, otherwise created.
-     The file is opened for write access only."
+     The file is opened for read/write access."
 
     |newStream|
     newStream := self new pathName:filename in:aDirectory.
@@ -107,6 +113,29 @@
     ^ newStream
 !
 
+newFileForWritingNamed:filename
+    "return a FileStream for new file named filename, aString.
+     If the file exists, it is truncated, otherwise created.
+     The file is opened for writeonly access."
+
+    |newStream|
+    newStream := self new pathName:filename.
+    newStream createForWriting isNil ifTrue:[^nil].
+    ^ newStream
+!
+
+newFileForWritingNamed:filename in:aDirectory
+    "return a FileStream for new file named filename, aString
+     in aDirectory, a FileDirectory.
+     If the file exists, it is truncated, otherwise created.
+     The file is opened for writeonly access."
+
+    |newStream|
+    newStream := self new pathName:filename in:aDirectory.
+    newStream createForWriting isNil ifTrue:[^nil].
+    ^ newStream
+!
+
 oldFileNamed:filename
     "return a FileStream for existing file named filename, aString.
      The file is opened for read/write access."
@@ -143,7 +172,8 @@
 
 fileNamed:filename
     "return a stream on file filename - if the file does not
-     already exist, create it."
+     already exist, create it.
+     The file is opened for read/write access."
 
     |stream|
 
@@ -156,7 +186,8 @@
 
 fileNamed:filename in:aDirectory
     "return a stream on file filename - if the file does not
-     already exist, create it."
+     already exist, create it.
+     The file is opened for read/write access."
 
     |stream|
 
@@ -200,7 +231,8 @@
 !
 
 appendingOldFileNamed:filename
-    "return a FileStream for existing file named filename, aString"
+    "return a FileStream for existing file named filename, aString.
+     The file is opened for writeonly access."
 
     |newStream|
     newStream := self new pathName:filename.
@@ -215,7 +247,8 @@
 
 appendingOldFileNamed:filename in:aDirectory
     "return a FileStream for existing file named filename, aString
-     in aDirectory, a FileDirectory"
+     in aDirectory, a FileDirectory.
+     The file is opened for writeonly access."
 
     |newStream|
     newStream := self new pathName:filename in:aDirectory.
@@ -302,9 +335,11 @@
 
     pathName isNil ifTrue:[^nil].
     (mode == #readonly) ifTrue: [
+        didWrite := false.
         ^ self openWithMode:'r'
     ].
     (mode == #writeonly) ifTrue: [
+        didWrite := true.
         ^ self openWithMode:'w'
     ].
     ^ self openWithMode:'r+'
@@ -361,6 +396,7 @@
      otherwise return the receiver."
 
     mode := #readonly.
+    didWrite := false.
     ^ self openWithMode:'r'
 !
 
@@ -370,6 +406,7 @@
      otherwise return the receiver."
 
     mode := #writeonly.
+    didWrite := true.
     ^ self openWithMode:'r+'   "unix-io does not allow this; open for update here"
 !
 
@@ -379,6 +416,7 @@
      otherwise return the receiver."
 
     mode := #writeonly.
+    didWrite := true.
     ^ self openWithMode:'a+'
 !
 
@@ -396,6 +434,7 @@
      If the file existed, its truncated; otherwise its created."
 
     mode := #writeonly.
+    didWrite := true.
     ^ self openWithMode:'w'
 !