Filename.st
changeset 14446 479f02b4c705
parent 14306 f41ca29d9b54
child 14512 1e72c974298e
equal deleted inserted replaced
14445:925f19f04bf7 14446:479f02b4c705
  5319     "return the binary contents of the file (as a byteArray);
  5319     "return the binary contents of the file (as a byteArray);
  5320      Raises an error, if the file is unreadable/non-existing."
  5320      Raises an error, if the file is unreadable/non-existing."
  5321     
  5321     
  5322     ^ self 
  5322     ^ self 
  5323         readingFileDo:[:s | 
  5323         readingFileDo:[:s | 
  5324             |nBytes bytes n|
  5324             |nBytes bytes n result|
  5325 
  5325 
  5326             s binary.
  5326             s binary.
  5327             nBytes := self fileSize.
  5327             nBytes := self fileSize.
  5328             (nBytes notNil and:[ nBytes ~~ 0 ]) ifTrue:[
  5328             (nBytes notNil and:[ nBytes ~~ 0 ]) ifTrue:[
  5329                 bytes := ByteArray uninitializedNew:nBytes.
  5329                 bytes := ByteArray uninitializedNew:nBytes.
  5330                 n := s 
  5330                 n := s nextBytes:nBytes into:bytes startingAt:1.
  5331                             nextBytes:nBytes
       
  5332                             into:bytes
       
  5333                             startingAt:1.
       
  5334                 n == nBytes ifTrue:[
  5331                 n == nBytes ifTrue:[
  5335                     bytes
  5332                     result := bytes
  5336                 ] ifFalse:[
  5333                 ] ifFalse:[
  5337                     bytes copyTo:n
  5334                     result := bytes copyTo:n
  5338                 ]
  5335                 ]
  5339             ] ifFalse:[
  5336             ] ifFalse:[
  5340                 s contentsOfEntireFile
  5337                 result := s contentsOfEntireFile
  5341             ]
  5338             ].
       
  5339             result
  5342         ]
  5340         ]
  5343 
  5341 
  5344     "
  5342     "
  5345      'Makefile' asFilename binaryContentsOfEntireFile
  5343      'Makefile' asFilename binaryContentsOfEntireFile
  5346      'foobar' asFilename binaryContentsOfEntireFile   
  5344      'foobar' asFilename binaryContentsOfEntireFile   
  5347     "
  5345     "
       
  5346 
       
  5347     "Modified: / 27-10-2012 / 19:42:07 / cg"
  5348 !
  5348 !
  5349 
  5349 
  5350 contents
  5350 contents
  5351     "return the contents of the file as a collection of lines;
  5351     "return the contents of the file as a collection of lines;
  5352      Raises an error, if the file is unreadable/non-existing.
  5352      Raises an error, if the file is unreadable/non-existing.
  5873 ! !
  5873 ! !
  5874 
  5874 
  5875 !Filename class methodsFor:'documentation'!
  5875 !Filename class methodsFor:'documentation'!
  5876 
  5876 
  5877 version
  5877 version
  5878     ^ '$Header: /cvs/stx/stx/libbasic/Filename.st,v 1.378 2012-08-10 10:49:56 stefan Exp $'
  5878     ^ '$Header: /cvs/stx/stx/libbasic/Filename.st,v 1.379 2012-10-27 17:44:35 cg Exp $'
  5879 !
  5879 !
  5880 
  5880 
  5881 version_CVS
  5881 version_CVS
  5882     ^ '$Header: /cvs/stx/stx/libbasic/Filename.st,v 1.378 2012-08-10 10:49:56 stefan Exp $'
  5882     ^ '$Header: /cvs/stx/stx/libbasic/Filename.st,v 1.379 2012-10-27 17:44:35 cg Exp $'
  5883 ! !
  5883 ! !
  5884 
  5884 
  5885 Filename initialize!
  5885 Filename initialize!