1 /* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
18 var fs = require('fs');
19 var assert = require('assert');
22 var srcFilePath = "../resources/test1.txt";
23 var dstFilePath = "../tmp/test_fs2.txt";
27 function onWrite(err, written, buffer) {
31 var fd = fs.openSync(dstFilePath, 'r');
32 var buffer = new Buffer(128);
33 fs.readSync(fd, buffer, 0, buffer.length, 0);
35 var result = 'TEST File Read & Write\n';
37 assert.equal(buffer.toString(), result);
41 function onOpenForWrite(err, fd) {
45 fs.write(fd, data, 0, data.length, onWrite);
49 function onRead(err, bytesRead, buffer) {
53 data = new Buffer(buffer.toString());
54 fs.open(dstFilePath, 'w', onOpenForWrite);
58 function onOpenForRead(err, fd) {
62 var buffer = new Buffer(128);
63 fs.read(fd, buffer, 0, buffer.length, 0, onRead);
67 fs.open(srcFilePath, 'r', onOpenForRead);