Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding seek-property to write-method #66

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -364,13 +364,14 @@ write()
*Writes content to a file.*

`write()` takes a `string` (path or filesystem URL) or `FileEntry` as it's first argument.
This is the file to write data to. If the does not exist, it is created. Otherwise,
the file's contents are overwritten if it already exists.
This is the file to write data to. If the does not exist, it is created. The file's contents are overwritten
if it already exists, unless the seek-property is defined in the second argument.

The second argument is an object with three properties:
The second argument is an object with four properties:
- `data`: the content to write into the file.
- `type`: optional mimetype of the content.
- `append`: optional true if data should be appended to the file.
- `seek`: optional integer indicating the position to start writing.

The success callback for this method is passed the `FileEntry` for the file that
was written to and the `FileWriter` object used to do the writing.
Expand Down
2 changes: 1 addition & 1 deletion component.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "filer.js",
"version": "0.4.5",
"version": "0.4.6",
"main": "./dist/filer.min.js"
}
40 changes: 20 additions & 20 deletions dist/filer.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "filer.js",
"version": "0.4.5",
"version": "0.4.6",
"description": "A wrapper library for the HTML5 Filesystem API what reuses UNIX commands (cp, mv, ls) for its API.",
"main": "src/filer.js",
"directories": {
Expand Down
7 changes: 5 additions & 2 deletions src/filer.js
Original file line number Diff line number Diff line change
Expand Up @@ -766,12 +766,15 @@ var Filer = new function() {

fileWriter.onerror = opt_errorHandler;

if (dataObj.append) {
if (dataObj.append || dataObj.seek) {
fileWriter.onwriteend = function(e) {
if (opt_successCallback) opt_successCallback(fileEntry, this);
};

fileWriter.seek(fileWriter.length); // Start write position at EOF.
// Start write position at EOF or supplied seek-position
var seekPosition = (dataObj.append && fileWriter.length) || dataObj.seek;

fileWriter.seek(seekPosition);
} else {
var truncated = false;
fileWriter.onwriteend = function(e) {
Expand Down
Loading