[View]  [Edit]  [Lock]  [References]  [Attachments]  [History]  [Home]  [Changes]  [Search]  [Help] 

test[nodeJS] 048 File truncation (sync)

"048-3 Tuncating file with #truncateSync:len:"
'Content generated by S8.Content generated by S8.Content generated by S8.' outputToFile: (TestPath,'Sample48-3.txt').
[NodeJS fs truncateSync: (TestPath,'Sample48-3.txt') len:1]
   on: Error
   do:[:ex| ^self error: '048-3 ', ex].


"048-4 Truncating file with #ftruncateSync:len:"
| fs |
fs := NodeJS fs.
fs open:(TestPath, 'Sample48-4.txt') flags:#w mode: 0666 with: [:error :fd| 
   error isNil ifFalse: [self error: '048-4 ' ,error].
   fs write: fd data: 'Content generated by S8.Content generated by S8.Content generated by S8' position: 0 encoding: #utf8 with:[:er :written :string|
      er isNil ifFalse: [^self error:'048-4 ', er].
      [fs fsyncSync: fd] 
         on: Error
         do: [:ex| ^self error: '048-4 ' ,ex].
      [fs ftruncateSync: fd len:1]
         on: Error
         do: [:ex| ^self error: '048-4 ' ,ex].
      fs closeSync:fd.
   ].   
].