-
Notifications
You must be signed in to change notification settings - Fork 66
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
utils: add AzFsExtraFile.appendFile #1525
Conversation
@@ -73,6 +73,12 @@ export namespace AzExtFsExtra { | |||
await workspace.fs.writeFile(uri, Buffer.from(contents)); | |||
} | |||
|
|||
export async function appendFile(resource: Uri | string, contents: string): Promise<void> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe a better name is appendToFile
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mimicking this https://www.geeksforgeeks.org/node-js-fs-appendfile-function/ so we can have a 1:1 conversion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you need to add the method to the declaration file?
Ah crap, I was thinking of the exports file. Yeah, I need to do that (and will do that with the bump) |
export async function appendFile(resource: Uri | string, contents: string): Promise<void> { | ||
const uri = convertToUri(resource); | ||
const existingContent = await AzExtFsExtra.readFile(uri); | ||
await AzExtFsExtra.writeFile(uri, existingContent + '\r\n\r\n' + contents); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to add the newlines though? Seems like separator should be the decision of the caller.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't have to, I was emulating what fs.appendFile
does though. We could have an option for "separator" though, I'd like to default to \r\n\r\n
since that is the default behavior of fs.appendFile
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that's a good middle ground.
No description provided.