Skip to content

Fetch steam inventories as a readable stream to reduce ram usage

License

Notifications You must be signed in to change notification settings

timvandam/steam-inventory-stream

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

steam-inventory-stream

The 'usual' way Steam inventories are usually fetched is using steam-tradeoffer-manager or 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

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')
})

About

Fetch steam inventories as a readable stream to reduce ram usage

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published