Title: Issue · GitHub
Open Graph Title: Issue · managedcode/Storage
X Title: Issue · managedcode/Storage
Description: Storage library provides a universal interface for accessing and manipulating data in different cloud blob storage providers - Issue · managedcode/Storage
Open Graph Description: Storage library provides a universal interface for accessing and manipulating data in different cloud blob storage providers - Issue · managedcode/Storage
X Description: Storage library provides a universal interface for accessing and manipulating data in different cloud blob storage providers - Issue · managedcode/Storage
Opengraph URL: https://github.com/managedcode/Storage
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"FileSystemStorage provider doesn't overwrite files correctly","articleBody":"If, using a MemoryStream, I write a 90kB file with name \"testfile.bin\" and then try to write 512 bytes afterwards, I expect the file to be overwritten such that the new total length of the file is 512 bytes.\r\n\r\nInstead, this library only overwrites the first e.g. 512 bytes and the file remains 90kB big.\r\n\r\nPlease see test case below:\r\n\r\n```c#\r\nusing ManagedCode.Storage.Core.Models;\r\nusing ManagedCode.Storage.FileSystem;\r\nusing ManagedCode.Storage.FileSystem.Options;\r\nusing Xunit.Abstractions;\r\n\r\nnamespace StorageFsMre;\r\n\r\npublic class MinimumExampleTest(ITestOutputHelper output)\r\n{\r\n [Fact]\r\n public async Task TestOverwritingFile()\r\n {\r\n var fsStorage = new FileSystemStorage(new FileSystemStorageOptions\r\n {\r\n BaseFolder = \"/tmp/\"\r\n });\r\n\r\n var myMemoryStream1 = new MemoryStream(90*1024);\r\n var buffer = new byte[90 * 1024];\r\n var random = new Random();\r\n random.NextBytes(buffer);\r\n myMemoryStream1.Write(buffer, 0, buffer.Length);\r\n\r\n // print them\r\n foreach (var b in myMemoryStream1.GetBuffer())\r\n {\r\n output.WriteLine(b.ToString());\r\n }\r\n\r\n var result = await fsStorage.UploadAsync(myMemoryStream1, new UploadOptions\r\n {\r\n FileName = \"testfile.bin\",\r\n }, CancellationToken.None);\r\n\r\n Assert.True(result.IsSuccess);\r\n\r\n var myMemoryStream2 = new MemoryStream(512);\r\n // write 512 bytes of 0x00\r\n myMemoryStream2.Write(new byte[512]);\r\n\r\n\r\n await fsStorage.UploadAsync(myMemoryStream2, new UploadOptions\r\n {\r\n FileName = \"testfile.bin\",\r\n }, CancellationToken.None);\r\n\r\n // check if the file exists\r\n var fileInfo = new FileInfo(\"/tmp/testfile.bin\");\r\n Assert.True(fileInfo.Exists);\r\n\r\n // check if the file has the correct size\r\n Assert.Equal(512, fileInfo.Length);\r\n\r\n // read the file in a new stream\r\n var readStream = new MemoryStream();\r\n using (var fileStream2 = fileInfo.OpenRead())\r\n {\r\n await fileStream2.CopyToAsync(readStream);\r\n }\r\n\r\n Assert.Equal(myMemoryStream2.ToArray(), readStream.ToArray());\r\n }\r\n}\r\n```","author":{"url":"https://github.com/lol768","@type":"Person","name":"lol768"},"datePublished":"2024-07-31T11:48:42.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/98/Storage/issues/98"}
| route-pattern | /:user_id/:repository/issues/:id(.:format) |
| route-controller | issues |
| route-action | show |
| fetch-nonce | v2:b8d67aa5-1e69-8ddc-6c96-19697da36571 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D244:102756:591F71C:7DBE280:6A5000D7 |
| html-safe-nonce | 450bc4d011383874a8d75bfce2d1cdda3b836b16cc13eda54d3dd5e7ee446758 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMjQ0OjEwMjc1Njo1OTFGNzFDOjdEQkUyODA6NkE1MDAwRDciLCJ2aXNpdG9yX2lkIjoiMzY0NDk3NjM5MTg0MDA3MTg5NiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | c86a53c8e7383a27abe67ac3d96a2f321d27437429ae00c2052c73c677686a18 |
| hovercard-subject-tag | repository:357467863 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/managedcode/Storage/issues/98 |
| twitter:image | https://opengraph.githubassets.com/81e852213210fdf4e37bc04a23a0c66b9d1e5015ae2e6a4ec3ee941584b85c8f/managedcode/Storage |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/81e852213210fdf4e37bc04a23a0c66b9d1e5015ae2e6a4ec3ee941584b85c8f/managedcode/Storage |
| og:image:alt | Storage library provides a universal interface for accessing and manipulating data in different cloud blob storage providers - Issue · managedcode/Storage |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 56eec25a3430492dd6ec2a480eb33256a0da5192d5714b0db4f5ab5f33203d94 |
| turbo-cache-control | no-cache |
| go-import | github.com/managedcode/Storage git https://github.com/managedcode/Storage.git |
| octolytics-dimension-user_id | 78253589 |
| octolytics-dimension-user_login | managedcode |
| octolytics-dimension-repository_id | 357467863 |
| octolytics-dimension-repository_nwo | managedcode/Storage |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 357467863 |
| octolytics-dimension-repository_network_root_nwo | managedcode/Storage |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | e155b8a71f9284454f73118dfe5e634e74f7afb3 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width