blob: 5bae05170ad9d16682f08b8e2856b4b3c96d9f8c [file] [log] [blame]
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
/// @assertion void writeAsBytesSync(
/// List<int> bytes, {
/// FileMode mode: FileMode.write,
/// bool flush: false
/// })
/// Synchronously write a list of bytes to a file.
///
/// Opens the file, writes the list of bytes to it and closes the file.
///
/// By default writeAsBytesSync creates the file for writing and truncates the
/// file if it already exists. In order to append the bytes to an existing file,
/// pass FileMode.append as the optional mode parameter.
///
/// If the flush argument is set to true data written will be flushed to the file
/// system before returning.
///
/// Throws a FileSystemException if the operation fails.
/// @description Checks that in a FileMode.writeOnlyAppend file is not
/// truncated
/// @author sgrekhov@unipro.ru
import "dart:io";
import "../../../Utils/expect.dart";
import "../file_utils.dart";
main() async {
await inSandbox(_main);
}
void _main(Directory sandbox) {
File file = getTempFileSync(parent: sandbox);
file.writeAsBytesSync([1, 1, 1, 1, 1]);
file.writeAsBytesSync([3, 1, 4, 1, 5], mode: FileMode.writeOnlyAppend);
Expect.listEquals([1, 1, 1, 1, 1, 3, 1, 4, 1, 5], file.readAsBytesSync());
}