-
Notifications
You must be signed in to change notification settings - Fork 6
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
[FIX] Resource: Keep stats size up to date #253
Conversation
Ensure size is always set when resource is modified.
lib/Resource.js
Outdated
@@ -76,6 +76,9 @@ class Resource { | |||
if (typeof string === "string" || string instanceof String) { |
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.
Shouldn't we rather call setString
/ setBuffer
in the constructor?
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.
done
|
||
t.is(resource.getStatInfo().size, 1337); | ||
}); | ||
|
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 should also add test cases when passing a real statInfo
to the constructor (from fs.stat) and then changing the content. This is the use case when a resource is created by the FsAdapter.
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.
done
Use "real" Stat object in test
improve constructor logic
lib/Resource.js
Outdated
@@ -74,7 +74,9 @@ class Resource { | |||
this._stream = stream || null; | |||
this._buffer = buffer || null; |
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.
This line can be removed
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.
Done
lib/Resource.js
Outdated
@@ -117,6 +119,7 @@ class Resource { | |||
this._buffer = buffer; | |||
this._contentDrained = false; | |||
this._streamDrained = false; | |||
this._setSize(Buffer.byteLength(this._buffer)); |
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.
Buffer.byteLength just returns the byteLength
from the buffer
this._setSize(Buffer.byteLength(this._buffer)); | |
this._setSize(this._buffer.byteLength); |
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.
Done
Maybe this is even a feature, to update the size when updating the content? |
Made tests work together with SAP/ui5-fs#253
As discussed today with @matz3 and @codeworrior: This does not work for resources where the content is updated using A possible alternative solution could be to provide an asynchronous |
Changed tests to use the buffer size for the size display when serving the index. Will work together with: SAP/ui5-fs#253
Stats.size was not set for a stream. To ensure Resource's size can be retrieved for: * stream * string * buffer async method is introduced which uses #getBuffer to ensure that size retrieval works for all content types. followup of #253
Stats.size was not set for a stream. To ensure Resource's size can be retrieved for: * stream * string * buffer async method is introduced which uses #getBuffer to ensure that size retrieval works for all content types. followup of #253
Ensure statInfo.size is always set when resource's content is modified.