How do you append to the file instead of overwriting it?
The file-system module documentation explains how to write to a file:
The following example writes some text to a file. It will create a new
file or overwrite an existing file.
var documents = fs.knownFolders.documents();
var file = documents.getFile("Test_Write.txt");
// Writing text to the file.
file.writeText("Something")
.then(function () {
// Succeeded writing to the file.
}, function (error) {
// Failed to write to the file.
});
My end goal is to write log files to disk as the nativescript app runs. It'd be too inefficient to read the contents of the log file into memory, append the new log message, and then write it all back to the file.
UPDATE:
Ended up logging to an sqlite database. This has some benefits and drawbacks, but for other's trying to solve a similar issue it's another direction to try.
NativeScript currently doesn't provide a appendFile function for its file system module.
Reference: https://github.com/NativeScript/NativeScript/issues/4462
A sample implementation of appendFile (text only) can be found here: https://github.com/EddyVerbruggen/nativescript-node/blob/dc93ab48a84c410bc8d6f46527fb171799f8bfeb/fs.js#L233-L254
It is using the "read and then write" method as you said.
Related
I have set up FilePond and it is working well but my next task is to preserve the order that files are added to FilePond.
I'm allowing multiple files to be added and have auto upload enabled but due to file size, transfer time and FilePond's asynchronous uploads it isn't possible to assume on the server side that the first to finish transfer was the first in the list.
I can see from the documentation that it's possible to get/remove files via their index so is it possible to use the file metadata plugin to send that index with each file uploaded.
Following on from #Rik's comment I have created the following code snippet which works well.
let filecount = 0;
pond.on('addfile', (file) => {
filecount += 1;
file.setMetadata("filecount", filecount);
... Other metadata removed for brevity ...
});
I'm building a Standalone app which will load a folder with c# code, and allow the user to write Regex to select and rename namespace/types/fields/properties/methods/argument/variable/events'name, but i'm stuck at renaming source code.
I have analyzed the SyntaxTree and collected all items, and also searched/matched/renamed with regex.
I have done a plenty of codes trying to get roslyn rename "items", but i only the first "item" is renamed while all the next ones are discarded.
I am aware of Immutability of the Syntax API, and after calling Renamer I save the solution, and also re-search the document in the new solution in the next loop.
//renaming code
var newSolution = await Renamer.RenameSymbolAsync(solution, isymbol, newName, solution.Workspace.Options).ConfigureAwait(false);
this.solution = newSolution;
//re-search code
if (solution.Projects.First ().ContainsDocument(doc.Document.Id)) {
var document = project.GetDocument(doc.Document.Id);
...
}
At the end i call SyntaxTree.GetRoot().ToString (); to get the final edited code, which as mentioned above has only the first edit.
Could anyone explain me the correct way to do this or provide me a sample how this could be implemented so i can try on my own?
I've a requirement to download a file from S3 based on a message content. In other words, the file to download is previously unknown, I've to search and find it at runtime. S3StreamingMessageSource doesn't seem to be a good fit because:
It relies on polling where as I need to wait for the message.
I can't find any way to create a S3StreamingMessageSource dynamically in the middle of a flow. gateway(IntegrationFlow) looks interesting but what I need is a gateway(Function<Message<?>, IntegrationFlow>) that doesn't exist.
Another candidate is S3MessageHandler but it has no support for listing files which I need for finding the desired file.
I can implement my own message handler using AWS API directly, just wondering if I'm missing something, because this doesn't seem like an unusual requirement. After all, not every app just sits there and keeps polling S3 for new files.
There is S3RemoteFileTemplate with the list() function which you can use in the handle(). Then split() result and call S3MessageHandler for each remote file to download.
Although the last one has functionality to download the whole remote dir.
For anyone coming across this question, this is what I did. The trick is to:
Set filters later, not at construction time. Note that there is no addFilters or getFilters method, so filters can only be set once, and can't be added later. #artem-bilan, this is inconvenient.
Call S3StreamingMessageSource.receive manually.
.handle(String.class, (fileName, h) -> {
if (messageSource instanceof S3StreamingMessageSource) {
S3StreamingMessageSource s3StreamingMessageSource = (S3StreamingMessageSource) messageSource;
ChainFileListFilter<S3ObjectSummary> chainFileListFilter = new ChainFileListFilter<>();
chainFileListFilter.addFilters(
new S3SimplePatternFileListFilter("**/*/*.json.gz"),
new S3PersistentAcceptOnceFileListFilter(metadataStore, ""),
new S3FileListFilter(fileName)
);
s3StreamingMessageSource.setFilter(chainFileListFilter);
return s3StreamingMessageSource.receive();
}
log.warn("Expected: {} but got: {}.",
S3StreamingMessageSource.class.getName(), messageSource.getClass().getName());
return messageSource.receive();
}, spec -> spec
.requiresReply(false) // in case all messages got filtered out
)
Question relates to http://sassdoc.com package
I would like to parse each *.scss file in ./source folder, but instead of generating sassdoc folder i would like to create partial-html for each parsed file. For example:
parse: variables.scss and receive variables.html, without page header, sidebar - pure content, even without html and body tags.
My current code:
var gulp = require('gulp'),
sassdoc = require('sassdoc');
var paths = {
scss: [
'source/**/*.scss'
]
};
gulp.task('sassdoc', function () {
console.log("sassdoc task finished");
return gulp.src(paths.scss)
.pipe(sassdoc());
});
It's not possible with SassDoc' default theme. So you'd need to build your own theme to acheive this.
http://sassdoc.com/using-your-own-theme
Each item is given a file key in resulting data, so I would leverage that and do some merging.
That could potentially end up in a sassdoc-extra custom filter.
http://sassdoc.com/extra-tools
EDIT:
Actually your question is quite misleanding, you want a variable.html file but with no html ...
If all that you want is the raw JSON data from SassDoc, without any kind of theme processing, then the parse method is what you're looking for.
But again, unless you call SassDoc on each file separately, you'll get all files together, meaning post data processing to split them, that's why a custom theme (even with no html output) is the way to go.
Firstly, I Want to read excel file which user is uploading and saving data to DB.
I have tried load function using excel API.
Excel::load($file_name_real, function($input) {
$results = $input->all();
// $input->dump();
})->download('xls');
But its not happening So now I want to move File to server then will read file then will unlink. By following function
$input1->move('/laravel');
But its not moving file.