FileStream.st
changeset 23898 4ac640e38157
parent 23894 2dcb46224ee8
child 24102 e14d73f12120
equal deleted inserted replaced
23897:cb46a48b02b5 23898:4ac640e38157
   908     ^ executor
   908     ^ executor
   909 ! !
   909 ! !
   910 
   910 
   911 
   911 
   912 !FileStream methodsFor:'misc functions'!
   912 !FileStream methodsFor:'misc functions'!
       
   913 
       
   914 copy:numberOfBytesOrNil into:outStream bufferSize:bufferSize
       
   915     "read from the receiver, and write numberOfBytes data to another aWriteStream.
       
   916      Return the number of bytes which have been transferred.
       
   917      If nuberOfBytesOrNil is nil, copy until the end of myself.
       
   918      Redefined to use operating system features to do a fast copy."
       
   919 
       
   920     |pos n nWritten|
       
   921 
       
   922     outStream isExternalStream ifTrue:[
       
   923         "sendfile() in Linux does not support any combination of file/pipe/socket fds.
       
   924          #copyFromFd:toFd:startIndex:count is curently not available in windows."
       
   925 
       
   926         pos := self position.
       
   927         numberOfBytesOrNil isNil ifTrue:[
       
   928             n := self size - pos.
       
   929         ] ifFalse:[
       
   930             n := numberOfBytesOrNil.
       
   931         ].
       
   932         nWritten := OperatingSystem
       
   933                         copyFromFd:self fileHandle
       
   934                         toFd:outStream fileHandle
       
   935                         startIndex:pos
       
   936                         count:n.
       
   937         nWritten > 0 ifTrue:[
       
   938             self position:pos+nWritten.
       
   939         ].
       
   940         nWritten = n ifTrue:[
       
   941             ^ self
       
   942         ].
       
   943     ].
       
   944 
       
   945     "fall back..."
       
   946     ^ super copy:numberOfBytesOrNil into:outStream bufferSize:bufferSize.
       
   947 
       
   948     "
       
   949      |in out|
       
   950 
       
   951      in := 'Make.proto' asFilename readStream.
       
   952      in copyToEndInto:Stdout.
       
   953      in close.
       
   954 
       
   955      |in out|
       
   956 
       
   957      in := 'Make.proto' asFilename readStream.
       
   958      out := '/tmp/test' asFilename writeStream.
       
   959      in copyToEndInto:out.
       
   960      in close. out close.
       
   961      '/tmp/test' asFilename contents.
       
   962     "
       
   963 
       
   964     "Created: / 13-03-2019 / 16:27:04 / Stefan Vogel"
       
   965 !
   913 
   966 
   914 syncFileSystem
   967 syncFileSystem
   915     "sync the filesystem containing this FileStream"
   968     "sync the filesystem containing this FileStream"
   916 
   969 
   917     OperatingSystem syncFileSystem:handle.
   970     OperatingSystem syncFileSystem:handle.