Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xujif/node_mmap_mio
A cross-platform memory-mapping library for nodejs(& TypeScript)
https://github.com/xujif/node_mmap_mio
Last synced: about 1 month ago
JSON representation
A cross-platform memory-mapping library for nodejs(& TypeScript)
- Host: GitHub
- URL: https://github.com/xujif/node_mmap_mio
- Owner: xujif
- License: mit
- Created: 2019-01-07T09:31:26.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2019-02-27T05:15:49.000Z (almost 6 years ago)
- Last Synced: 2024-11-28T20:50:27.210Z (about 1 month ago)
- Language: C++
- Homepage:
- Size: 33.2 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
## mmap-mio
A cross-platform memory-mapped library for nodejs(& TypeScript).
powered by [mio (C++11 cross-platform memory mapping library)](https://github.com/mandreyel/mio)
and [node-addon-api](https://github.com/nodejs/node-addon-api)* TypeScript support.
* only support node 8.0+.
* gc friendly.### Usage
```javascript
const { mmap ,mmap_ro } = require('mmap-mio')
const m = mmap('./file.hex')
const ro = mmap_ro('./file.hex') // for read-only mode
const buffer = m.buffer() // get file Buffer
// buffer.toString()
// buffer[0] = 65
// const byte = buffer[123]
m.sync() // force flush changes to disk.
m.unmap() // unmap the file. Note: do not access the buffer after unmapped;```
### Api
```TypeScript
/**
* Creates an instance of MappedFile.
*
* @export
* @param {(string | number)} path_or_fd
* @param {number} [offset]
* @param {number} [size_to_map]
* @returns {MappedFile}
*/
function mmap(path_or_fd: string | number, offset?: number, size_to_map ?: number): MappedFile/**
* Creates an instance of ReadOnlyMappedFile.
*
* @export
* @param {(string | number)} path_or_fd
* @param {number} [offset]
* @param {number} [size_to_map]
* @returns {ReadOnlyMappedFile}
*/
function mmap_ro(path_or_fd: string | number, offset ?: number, size_to_map ?: number): ReadOnlyMappedFile// same as ReadOnlyMappedFile
class MappedFile {constructor(path_or_fd: string | number, offset ?: number, size_to_map ?: number);
readonly writable: boolean
readonly length: number // mapped length
readonly offset: number
buffer(offset?:number,length?:number): Buffer // get the buffer of mapped data
size(): number // mapped length same with .length
isMapped(): boolean
unmap(): void // unmap the file
sync(): void // flush changes to disk
}
```