[View] [Edit] [Lock] [References] [Attachments] [History] [Home] [Changes] [Search] [Help]
test[nodeJS] 043 File Write (async)
"043-8 Writing files with #write:buffer:offset:length:position:with:"
| fs data text|
fs := NodeJS fs.
text := 'YYZ'.
fs open: (TestPath, 'Sample43-8.txt') flags:#w mode: 0666 with: [:error :fd|
error isNil ifFalse: [^self error: '043-8 ' ,error].
jsObject := {'new Buffer(3);'}.
data := (NodeBuffer @ jsObject).
data write: text.
fs write: fd buffer: data offset: 0 length: (data length) position: 0 with:[:er :written :buf|
er isNil ifFalse: [^self error:'043-8 ', er].
fs closeSync:fd.
]
].
"043-9 Writing files with #write:data:position:encoding:with:"
| fs text |
fs := NodeJS fs.
text := 'YYZ'.
fs open:(TestPath, 'Sample43-9.txt') flags:#w mode: 0666 with: [:error :fd|
error isNil ifFalse: [self error: '043-9 ' ,error].
fs write: fd data: text position: 0 encoding: #utf8 with:[:er :written :string|
er isNil ifFalse: [^self error:'043-9 ', er].
fs closeSync:fd.
]
].
"043-10 Writing files with #writeFile:data:options:with:"
| options |
options := ((#encoding -> #utf8),(#mode -> 0666),(#flag -> #w)).
NodeJS fs writeFile: (TestPath, 'Sample43-10.txt') data: 'YYZ' options: options with: [:error |
error isNil ifFalse: [^self error: '043-10 ' ,error]
].