Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/timvandam/steam-inventory-stream
Fetch steam inventories as a readable stream to reduce ram usage
https://github.com/timvandam/steam-inventory-stream
Last synced: 2 months ago
JSON representation
Fetch steam inventories as a readable stream to reduce ram usage
- Host: GitHub
- URL: https://github.com/timvandam/steam-inventory-stream
- Owner: timvandam
- License: mit
- Created: 2020-04-08T15:23:12.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-04-15T11:11:53.000Z (over 4 years ago)
- Last Synced: 2024-10-02T22:04:27.428Z (2 months ago)
- Language: JavaScript
- Size: 19.5 KB
- Stars: 8
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-steam - steam-inventory-stream - Fetch inventories as readable streams. (Packages / Node.js)
README
# steam-inventory-stream
The 'usual' way Steam inventories are usually fetched is using [steam-tradeoffer-manager](https://github.com/DoctorMcKay/node-steam-tradeoffer-manager) or [steamcommunity](https://github.com/DoctorMcKay/node-steamcommunity). Unfortunately these modules don't support streams, which means that all items in the inventory being loaded will be saved to memory.
This package provides an alternative by streaming these items instead, reducing memory usage when used correctly.
## Installation
`$ npm install steam-inventory-stream``$ yarn add steam-inventory-stream`
## Usage
```javascript
const SteamInventoryStream = require('steam-inventory-stream')
const inventoryStream = new SteamInventoryStream(
steamId,
appId,
contextId,
[language=en],
[maxSequentialErrors=5],
[maxChunkSize=5000]
)/**
* steamId must be a string
* appId must be a number
* contextId must be a string
* language must be a string (default = en)
* maxSequentialErrors is the amount of times Steam can return an error code in a row before stopping loading items (default = 5)
* maxChunkSize is the maximum amount of items to fetch per request (default = 5000). Values above 5000 are not allowed by Steam
*/// You can now use `inventoryStream` just like any other readable stream, e.g.:
inventoryStream.on('data', items => {
// `items` is an array of SteamItem (lib/SteamItem.js) instances
console.log(`Fetched ${items.length} items`)
})inventoryStream.on('end', () => {
console.log('All items have been fetched')
})
```