From 80876f6e604f3e1e56b993dde3c9406abb85b570 Mon Sep 17 00:00:00 2001 From: hackertron Date: Sun, 21 Jan 2018 10:11:14 +0530 Subject: [PATCH 1/6] added example for flush() --- src/io/files.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/io/files.js b/src/io/files.js index 8c1f87756a..0b722b554c 100644 --- a/src/io/files.js +++ b/src/io/files.js @@ -1126,6 +1126,17 @@ p5.PrintWriter = function(filename, extension) { }; /** * @method flush + * @example + *
+ * // create writer object + * var writer = createWriter('newFile.txt'); + * writer.write(['Flush me']); + * // flush writer object here + * writer.flush(); + * // close writer + * writer.close(); + *
+ * */ this.flush = function() { this.content = ''; From 62be35eb14c87e7764517192dbc632a7965648b0 Mon Sep 17 00:00:00 2001 From: hackertron Date: Mon, 22 Jan 2018 23:04:16 +0530 Subject: [PATCH 2/6] updated flush method example with description --- src/io/files.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/io/files.js b/src/io/files.js index 0b722b554c..3886390911 100644 --- a/src/io/files.js +++ b/src/io/files.js @@ -1125,6 +1125,7 @@ p5.PrintWriter = function(filename, extension) { this.content += data + '\n'; }; /** + * Flushes the PrintWriter object that calls it * @method flush * @example *
From a50af964e3c25fe0b968002e90b93de879e60830 Mon Sep 17 00:00:00 2001 From: hackertron Date: Tue, 23 Jan 2018 18:52:05 +0530 Subject: [PATCH 3/6] update --- src/io/files.js | 105 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 92 insertions(+), 13 deletions(-) diff --git a/src/io/files.js b/src/io/files.js index 3886390911..b0b6992107 100644 --- a/src/io/files.js +++ b/src/io/files.js @@ -1111,39 +1111,118 @@ p5.PrintWriter = function(filename, extension) { this.content = ''; //Changed to write because it was being overloaded by function below. /** + * Writes data to the PrintWriter stream * @method write - * @param {Array} data + * @param {Array} data all data to be written by the PrintWriter + * @example + *
+ * + * // creates a file called 'newFile.txt' + * var writer = createWriter('newFile.txt'); + * // write 'Hello world!'' to the file + * writer.write(['Hello world!']); + * // close the PrintWriter and save the file + * writer.close(); + * + *
+ *
+ * + * // creates a file called 'newFile2.txt' + * var writer = createWriter('newFile2.txt'); + * // write 'apples,bananas,123' to the file + * writer.write(['apples', 'bananas', 123]); + * // close the PrintWriter and save the file + * writer.close(); + * + *
+ *
+ * + * // creates a file called 'newFile3.txt' + * var writer = createWriter('newFile3.txt'); + * // write 'My name is: Teddy' to the file + * writer.write('My name is:'); + * writer.write(' Teddy'); + * // close the PrintWriter and save the file + * writer.close(); + * + *
*/ this.write = function(data) { this.content += data; }; /** + * Writes data to the PrintWriter stream, and adds a new line at the end * @method print - * @param {Array} data + * @param {Array} data all data to be printed by the PrintWriter + * @example + *
+ * + * // creates a file called 'newFile.txt' + * var writer = createWriter('newFile.txt'); + * // creates a file containing + * // My name is: + * // Teddy + * writer.print('My name is:'); + * writer.print('Teddy'); + * // close the PrintWriter and save the file + * writer.close(); + * + *
+ *
+ * + * var writer; + * + * function setup() { + * createCanvas(400, 400); + * // create a PrintWriter + * writer = createWriter('newFile.txt'); + * } + * + * function draw() { + * // print all mouseX and mouseY coordinates to the stream + * writer.print([mouseX, mouseY]); + * } + * + * function mouseClicked() { + * // close the PrintWriter and save the file + * writer.close(); + * } + * + *
*/ this.print = function(data) { this.content += data + '\n'; }; /** - * Flushes the PrintWriter object that calls it + * Flushes the PrintWriter object * @method flush * @example - *
- * // create writer object - * var writer = createWriter('newFile.txt'); - * writer.write(['Flush me']); - * // flush writer object here - * writer.flush(); - * // close writer - * writer.close(); - *
- * */ this.flush = function() { this.content = ''; }; /** + * Closes the PrintWriter * @method close + * @example + *
+ * + * // create a file called 'newFile.txt' + * var writer = createWriter('newFile.txt'); + * // close the PrintWriter and save the file + * writer.close(); + * + *
+ *
+ * + * // create a file called 'newFile2.txt' + * var writer = createWriter('newFile2.txt'); + * // write some data to the file + * writer.write([100, 101, 102]); + * // close the PrintWriter and save the file + * writer.close(); + * + *
*/ this.close = function() { // convert String to Array for the writeFile Blob From 8112706b90ec24cea9c7a90d000fcc4f5efaf672 Mon Sep 17 00:00:00 2001 From: hackertron Date: Tue, 23 Jan 2018 18:52:39 +0530 Subject: [PATCH 4/6] update --- package.json | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 1a134ee8eb..d607e3487a 100644 --- a/package.json +++ b/package.json @@ -40,15 +40,19 @@ "devDependencies": { "all-contributors-cli": "^4.5.0", "amdclean": "~0.3.3", + "brfs": "^1.4.3", "browserify": "^11.0.1", "chai": "^3.5.0", "concat-files": "^0.1.0", "connect-modrewrite": "^0.10.1", "derequire": "^2.0.0", + "es6-promise": "^4.1.1", "eslint": "^4.9.0", "eslint-config-prettier": "2.7.0", "eslint-plugin-prettier": "2.3.1", "esprima-extract-comments": "^0.2.1", + "fetch-jsonp": "^1.1.3", + "file-saver": "^1.3.3", "grunt": "^0.4.5", "grunt-cli": "^0.1.13", "grunt-contrib-compress": "^1.4.3", @@ -87,19 +91,14 @@ "lint-staged": "^4.3.0", "marked": "^0.3.9", "mocha": "^4.1.0", + "opentype.js": "^0.7.3", "prettier": "^1.7.4", "request": "^2.81.0", + "whatwg-fetch": "^2.0.3", "word-wrap": "^1.2.3" }, "license": "LGPL-2.1", "dependencies": { - "brfs": "^1.4.3", - "es6-promise": "^4.1.1", - "fetch-jsonp": "^1.1.3", - "file-saver": "^1.3.3", - "npm": "^5.5.1", - "opentype.js": "^0.7.3", - "whatwg-fetch": "^2.0.3" }, "main": "./lib/p5.js", "types": "./lib/p5.d.ts", From 07d65451ed1d287c0313c8cf45d834094c5fa04d Mon Sep 17 00:00:00 2001 From: hackertron Date: Tue, 23 Jan 2018 19:01:23 +0530 Subject: [PATCH 5/6] description for flush() --- src/io/files.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/io/files.js b/src/io/files.js index b0b6992107..1ab7d05038 100644 --- a/src/io/files.js +++ b/src/io/files.js @@ -1194,9 +1194,19 @@ p5.PrintWriter = function(filename, extension) { this.content += data + '\n'; }; /** - * Flushes the PrintWriter object + * clears the data that is written to PrintWriter object. * @method flush * @example + *
+ * // create writer object + * var writer = createWriter('newFile.txt'); + * writer.write(['Flush me']); + * // flush writer object here + * writer.flush(); + * // close writer + * writer.close(); + *
+ * */ this.flush = function() { this.content = ''; From 5e739e8ee2e4e591de753c2a3bc024d1152afc45 Mon Sep 17 00:00:00 2001 From: hackertron Date: Tue, 23 Jan 2018 19:17:06 +0530 Subject: [PATCH 6/6] resolved merge conflict --- src/io/files.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/io/files.js b/src/io/files.js index 2c2ee92714..36fdb4f937 100644 --- a/src/io/files.js +++ b/src/io/files.js @@ -1194,6 +1194,19 @@ p5.PrintWriter = function(filename, extension) { this.content += data + '\n'; }; /** + * Clears the data already written to the PrintWriter object + * @method flush + * @example + *
+ * // create writer object + * var writer = createWriter('newFile.txt'); + * writer.write(['Flush me']); + * // flush writer object here + * writer.flush(); + * // close writer + * writer.close(); + *
+ * */ this.flush = function() { this.content = '';