aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2014-06-11 13:47:35 -0700
committerAlon Zakai <alonzakai@gmail.com>2014-06-11 13:48:59 -0700
commitd2768d2eee9075c3d0c5f4222f463b6bca2b9194 (patch)
tree92a15a5f32bb48c576353e99dd76dac83504aa20
parentbd5acc202250c11ac85a7b8bb7eae0540634c061 (diff)
fix bug introduced in 92cab32f5f where we ignore the current offset in a file when writing initial data to it
-rw-r--r--src/library_memfs.js5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/library_memfs.js b/src/library_memfs.js
index 24d6cc22..72ecdcfe 100644
--- a/src/library_memfs.js
+++ b/src/library_memfs.js
@@ -291,10 +291,13 @@ mergeInto(LibraryManager.library, {
#if USE_TYPED_ARRAYS == 2
if (buffer.subarray && (!node.contents || node.contents.subarray)) { // This write is from a typed array to a typed array?
if (canOwn) { // Can we just reuse the buffer we are given?
+#if ASSERTIONS
+ assert(position === 0, 'canOwn must imply no weird position inside the file');
+#endif
node.contents = buffer.subarray(offset, offset + length);
node.usedBytes = length;
return length;
- } else if (node.usedBytes === 0) { // If this first write to an empty file, do a fast set since we don't need to care about old data.
+ } else if (node.usedBytes === 0 && position === 0) { // If this is a simple first write to an empty file, do a fast set since we don't need to care about old data.
node.contents = new Uint8Array(buffer.subarray(offset, offset + length));
node.usedBytes = length;
return length;