{"id":17399224,"url":"https://github.com/feross/typedarray-to-buffer","last_synced_at":"2025-04-04T19:13:17.109Z","repository":{"id":15810079,"uuid":"18549659","full_name":"feross/typedarray-to-buffer","owner":"feross","description":"Convert a typed array to a Buffer without a copy.","archived":false,"fork":false,"pushed_at":"2020-11-23T21:17:47.000Z","size":42,"stargazers_count":66,"open_issues_count":0,"forks_count":16,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-10-29T12:59:27.584Z","etag":null,"topics":["browser","browserify","buffer","javascript","nodejs","typed-arrays","typedarray"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/feross.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-04-08T07:47:51.000Z","updated_at":"2024-10-23T12:56:48.000Z","dependencies_parsed_at":"2022-09-26T20:31:44.497Z","dependency_job_id":null,"html_url":"https://github.com/feross/typedarray-to-buffer","commit_stats":null,"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/feross%2Ftypedarray-to-buffer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/feross%2Ftypedarray-to-buffer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/feross%2Ftypedarray-to-buffer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/feross%2Ftypedarray-to-buffer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/feross","download_url":"https://codeload.github.com/feross/typedarray-to-buffer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245516743,"owners_count":20628212,"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":["browser","browserify","buffer","javascript","nodejs","typed-arrays","typedarray"],"created_at":"2024-10-16T15:13:27.015Z","updated_at":"2025-03-28T18:15:47.483Z","avatar_url":"https://github.com/feross.png","language":"JavaScript","readme":"# typedarray-to-buffer [![travis][travis-image]][travis-url] [![npm][npm-image]][npm-url] [![downloads][downloads-image]][downloads-url] [![javascript style guide][standard-image]][standard-url]\n\n[travis-image]: https://img.shields.io/travis/feross/typedarray-to-buffer/master.svg\n[travis-url]: https://travis-ci.org/feross/typedarray-to-buffer\n[npm-image]: https://img.shields.io/npm/v/typedarray-to-buffer.svg\n[npm-url]: https://npmjs.org/package/typedarray-to-buffer\n[downloads-image]: https://img.shields.io/npm/dm/typedarray-to-buffer.svg\n[downloads-url]: https://npmjs.org/package/typedarray-to-buffer\n[standard-image]: https://img.shields.io/badge/code_style-standard-brightgreen.svg\n[standard-url]: https://standardjs.com\n\n#### Convert a typed array to a [Buffer](https://github.com/feross/buffer) without a copy.\n\n[![saucelabs][saucelabs-image]][saucelabs-url]\n\n[saucelabs-image]: https://saucelabs.com/browser-matrix/typedarray-to-buffer.svg\n[saucelabs-url]: https://saucelabs.com/u/typedarray-to-buffer\n\nSay you're using the ['buffer'](https://github.com/feross/buffer) module on npm, or\n[browserify](http://browserify.org/) and you're working with lots of binary data.\n\nUnfortunately, sometimes the browser or someone else's API gives you a typed array like\n`Uint8Array` to work with and you need to convert it to a `Buffer`. What do you do?\n\nOf course: `Buffer.from(uint8array)`\n\nBut, alas, every time you do `Buffer.from(uint8array)` **the entire array gets copied**.\nThe `Buffer` constructor does a copy; this is\ndefined by the [node docs](http://nodejs.org/api/buffer.html) and the 'buffer' module\nmatches the node API exactly.\n\nSo, how can we avoid this expensive copy in\n[performance critical applications](https://github.com/feross/buffer/issues/22)?\n\n***Simply use this module, of course!***\n\nIf you have an `ArrayBuffer`, you don't need this module, because\n`Buffer.from(arrayBuffer)`\n[is already efficient](https://nodejs.org/api/buffer.html#buffer_class_method_buffer_from_arraybuffer_byteoffset_length).\n\n## install\n\n```bash\nnpm install typedarray-to-buffer\n```\n\n## usage\n\nTo convert a typed array to a `Buffer` **without a copy**, do this:\n\n```js\nvar toBuffer = require('typedarray-to-buffer')\n\nvar arr = new Uint8Array([1, 2, 3])\narr = toBuffer(arr)\n\n// arr is a buffer now!\n\narr.toString()  // '\\u0001\\u0002\\u0003'\narr.readUInt16BE(0)  // 258\n```\n\n## how it works\n\nIf the browser supports typed arrays, then `toBuffer` will **augment the typed array** you\npass in with the `Buffer` methods and return it. See [how does Buffer\nwork?](https://github.com/feross/buffer#how-does-it-work) for more about how augmentation\nworks.\n\nThis module uses the typed array's underlying `ArrayBuffer` to back the new `Buffer`. This\nrespects the \"view\" on the `ArrayBuffer`, i.e. `byteOffset` and `byteLength`. In other\nwords, if you do `toBuffer(new Uint32Array([1, 2, 3]))`, then the new `Buffer` will\ncontain `[1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0]`, **not** `[1, 2, 3]`. And it still doesn't\nrequire a copy.\n\nIf the browser doesn't support typed arrays, then `toBuffer` will create a new `Buffer`\nobject, copy the data into it, and return it. There's no simple performance optimization\nwe can do for old browsers. Oh well.\n\nIf this module is used in node, then it will just call `Buffer.from`. This is just for\nthe convenience of modules that work in both node and the browser.\n\n## license\n\nMIT. Copyright (C) [Feross Aboukhadijeh](http://feross.org).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffeross%2Ftypedarray-to-buffer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffeross%2Ftypedarray-to-buffer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffeross%2Ftypedarray-to-buffer/lists"}