{"id":22835188,"url":"https://github.com/jchristn/slidingwindow","last_synced_at":"2025-04-24T00:07:35.171Z","repository":{"id":63442724,"uuid":"196519493","full_name":"jchristn/SlidingWindow","owner":"jchristn","description":"SlidingWindow provides an interface to retrieve chunks from a byte array using a sliding window.","archived":false,"fork":false,"pushed_at":"2022-01-07T16:27:51.000Z","size":1924,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-24T00:07:25.320Z","etag":null,"topics":["bytes","data","processing","sliding-window","slidingwindow","stream"],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jchristn.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":["jchristn"],"custom":["https://paypal.me/joelchristner"]}},"created_at":"2019-07-12T06:13:34.000Z","updated_at":"2023-06-16T21:56:42.000Z","dependencies_parsed_at":"2022-11-19T02:04:41.600Z","dependency_job_id":null,"html_url":"https://github.com/jchristn/SlidingWindow","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jchristn%2FSlidingWindow","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jchristn%2FSlidingWindow/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jchristn%2FSlidingWindow/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jchristn%2FSlidingWindow/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jchristn","download_url":"https://codeload.github.com/jchristn/SlidingWindow/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250535099,"owners_count":21446508,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bytes","data","processing","sliding-window","slidingwindow","stream"],"created_at":"2024-12-12T22:08:38.406Z","updated_at":"2025-04-24T00:07:35.133Z","avatar_url":"https://github.com/jchristn.png","language":"C#","funding_links":["https://github.com/sponsors/jchristn","https://paypal.me/joelchristner"],"categories":[],"sub_categories":[],"readme":"# SlidingWindow\n\nSlidingWindow provides an interface to retrieve chunks from a byte array using a sliding window.\n\n## Use Cases\n\nSlidingWindow is helpful for use cases that require examination of a sliding window of bytes within a byte array.  For instance, SlidingWindow is useful for cryptographic and compression use cases.\n\n## How It Works\n\nInitialize SlidingWindow with a byte array over which you would like to iterate using a SlidingWindow.\n\nSpecify the desired window size in ```chunkSize```.\n\nCall ```GetNextChunk()``` to retrieve the next window of data.  As you retrieve chunks, the window will advance by the number of bytes defined in ```shiftSize```.\n\nOn the last chunk, if fewer than ```chunkSize``` bytes remain, the remaining bytes will be returned, and ```out finalChunk``` will be set to true, indicating the end of the byte array.\n\n## Example\n\nSuppose you have the sentence ```The quick brown fox jumped over the lazy dog...```, which is 47 bytes long.\n```\n         1         2         3         4         5\n12345678901234567890123456789012345678901234567890\nThe quick brown fox jumped over the lazy dog...\n```\n\nInitializing the ```Bytes``` class with this byte array, a ```chunkSize``` of ```24``` and a sliding window of ```8``` would result in the following:\n\n```csharp\nusing SlidingWindow;\n\nstring strData = \"The quick brown fox jumped over the lazy dog...\"\nbyte[] byteData = Encoding.UTF8.GetBytes(strData);\nBytes slidingWindow = new Bytes(byteData, 24, 8);\n\nint chunks = slidingWindow.ChunkCount();  // 4\n\nint position = 0;         // zero-based index of current chunk\nbyte[] chunk = null;      // all of the data in the window\nbyte[] newData = null;    // new data retrieved from the previous chunk\nbool finalChunk = false;  // whether or not it's the last chunk\n\nchunk = slidingWindow.GetNextChunk(out position, out newData, out finalChunk);  \n// position   : 0\n// chunk      : 'The quick brown fox jump'\n// newData    : 'The quick brown fox jump'\n// finalChunk : false\n\nchunk = slidingWindow.GetNextChunk(out position, out newData, out finalChunk);  \n// position   : 8\n// chunk      : 'k brown fox jumped over '\n// newData    : 'ed over '\n// finalChunk : false\n\nchunk = slidingWindow.GetNextChunk(out position, out newData, out finalChunk);  \n// position   : 16\n// chunk      : 'fox jumped over the lazy'\n// newData    : 'the lazy'\n// finalChunk : false\n\nchunk = slidingWindow.GetNextChunk(out position, out newData, out finalChunk);  \n// position   : 24\n// chunk      : 'ed over the lazy dog...'\n// newData    : ' dog...'\n// finalChunk : true\n```\n\n```chunkSize``` must be greater than zero and less than the length of the supplied data, and ```shiftSize``` must be greater than zero and less than ```chunkSize```.\n\n## New in v1.0.x\n\n- Initial release with support for byte arrays.\n- Added support for net452.\n- Added support for streams where the content length is known.\n- Added out param for position at which the chunk starts from the source byte array or stream.\n- Added out param for byte array containing the new data from the previous chunk included in the returned chunk.\n \n## Version History\n\nPlease refer to CHANGELOG.md.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjchristn%2Fslidingwindow","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjchristn%2Fslidingwindow","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjchristn%2Fslidingwindow/lists"}